8000 Slow performance with 100 children · Issue #136 · getoutreach/epf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Slow performance with 100 children #136
Open
@stas-sl

Description

@stas-sl

Hi.

I have a model with ~100 child models. When I load it for the first time (with sideloading children), it loads quite fast. But if I'd like to reload it from server for the second time it takes much much longer.

Am I using it wrong way? How do you use it in your applications? Or you have only relatively small number of models? Or you do not reload them if they are already loaded? But what if something changed on the server?

Another idea I had is to use session.remove for all posts and comments before loading them for the second time. But I got strange errors after removing and loading again. Seems like remove doesn't clear everything correctly. Is remove supposed to be used in such scenarios?

describe "rest", ->

  adapter = null
  session = null

  beforeEach ->
    require('./_shared').setupRest.apply(this)
    adapter = @adapter
    session = @session
    Ep.__container__ = @container

    class @Post extends Ep.Model
      comments: Ep.hasMany 'comment'

    @App.Post = @Post

    class @Comment extends Ep.Model
      post: Ep.belongsTo 'post'

    @App.Comment = @Comment

    @container.register 'model:post', @Post
    @container.register 'model:comment', @Comment

  afterEach ->
    delete Ep.__container__

  context 'post with 100 comments', ->
    beforeEach ->
      adapter.r['GET:/posts'] = posts: [{id: 1, comments: [1..100]}],
      comments: ({id: num, post: 1} for num in [1..100])

    it 'fresh load works relatively fast', ->
      session.query('post').then (posts) ->
        expect(posts[0].comments.length).to.eq(100)

    it 'load if post and comments already in session is very slow', ->
      session.query('post').then (posts) ->
        session.query('post').then (posts) ->
          expect(posts[0].comments.length).to.eq(100)
  rest
    post with 100 comments
      ✓ fresh load works relatively fast (386ms)
      ✓ load if post and comments already in session is very slow (19613ms)


  2 passing (20s)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0