Skip to content

scopes can get out of sync #375

Closed
Closed
@catmando

Description

if data is fetched at the same time as a new record is created.

For example
on_client { SomeModel.first.other_models.count } # <- causes a fetch, while we are fetching we do:
OtherModels.create(some_model: SomeModel.first) # <- if timing is just right...
expect { SomeModel.first.other_models.count }.to_on_client eq(2) # <- returns 3!

Why? if the timing is just right, the new model will get created while the fetch is being calculated, but if the after commit hook is delayed, and finishes, AFTER the fetch returns, then we end up adding the new model on, even though the fetch found it was there.

The solution will be to include the time that the model is created/updated/destroyed in the data packet to the client, and to compare this with the time stamp that the scope was last updated by a fetch. If the fetch was sent AFTER the time stamp of the broadcast, then the scope is invalidated, and will be refetched.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingready-to-releaseInternal Use Only: Has been fixed, specs passing and pushed to edge branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions