Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use localStorage to cache incidents and synchronize data across contexts #96

Open
wsanchez opened this issue Aug 2, 2016 · 7 comments
Milestone

Comments

@wsanchez
Copy link
Member

wsanchez commented Aug 2, 2016

Use localStorage to cache incidents and synchronize data across contexts

We load every incident when we open the dispatch queue, then again when we open each incident.

When incident data gets edited in one context (tab/window/etc.), it does not update in others. That can also be fixed by monitoring local storage events.

@wsanchez wsanchez added this to the Burning Man 2016 milestone Aug 2, 2016
@wsanchez
Copy link
Member Author

wsanchez commented Aug 2, 2016

Some useful info on this in #92.

@wsanchez
Copy link
Member Author

wsanchez commented Aug 3, 2016

The need to synchronize incident data across contexts is reduced a bit by the fix for #92 we we still can have the dispatch queue and the open incident both open, and we do want those to stay in sync.

And we also want shared loading and caching between the dispatch queue and the incidents.

If we start with the shared cache, then the remaining thing is that when one page updates an incident, that the others notice and load from the cache. So let's start with the caching.

Looks like lscache doesn't have good support support for listening to events (there's a ticket open for it), so we may want to avoid using that for incidents, though I like the idea of an expiration, in case of failures to invalidate the cache.

A danger here is that we don't want to fill the allowable caching size per origin, so we need to figure out a way to measure our usage and make sure we stay under it. Apparently that's 5MB in pretty much every browser. lscache has a convenient API for flushing everything, which would be really handy if we could detect a full cache (eg. you opened every event's queue and therefore cached all incidents in all events). But again, seems like we can't use it.

@wsanchez wsanchez self-assigned this Aug 3, 2016
@wsanchez
Copy link
Member Author

wsanchez commented Aug 3, 2016

Actually, it looks like the keys that lscache uses internally are simply the given keys with an lscache- prefix, so setting up change events on that should be as simple as direct usage of local storage, though without an API, we need to beware that this is an abstraction violation that can bite us later if we upgrade lscache versions.

@wsanchez
Copy link
Member Author

wsanchez commented Aug 3, 2016

Wait, we can't have caching without server push because if an operator on another host (or same operator on another browser) makes a change, we won't see it, even on reload, until the cache expires.

So we can only use local storage for cross-context sync and any reload of an incident page… or the dispatch queue… should always reload data from the server to make sure it's relatively up-to-date.

There's some monkey business we can do to display from cache then reload then update the view, but we have to be cautious about caching traps here.

@wsanchez
Copy link
Member Author

wsanchez commented Aug 3, 2016

ie… I got ahead of myself. @kimballa's single-user suggestion in #92 is a valid strategy that doesn't include the above monkey business. I'd still keep the expirations in lscache, probably set to a minute.

@wsanchez
Copy link
Member Author

wsanchez commented Aug 3, 2016

I should stop talking to myself and go to sleep, as I'm unclear that I'm being clear and/or coherent.

However, I'll note that I'm not especially worried about some of the concerns expressed in #92 about stomping on a user edit-in-progress because edits to the metadata fields (ie. not adding a report entry) are small and somewhat disposable, and because causing an update in another tab is unlikely to stomp on such an edit-in-progress given how the UI works, which is that when you exit a field, it's sent to the server as a field-specific edit (that is "update summary to X").

Any pending edits to report text, which a user could very rightfully be very annoyed by any stompage won't happen, because the report entries are append-only, and an incident refresh should not clear the new-entry-to-add text field.

@wsanchez
Copy link
Member Author

Punting this because #46 is even better and I have that working. We may still want localStorage for caching/performance reasons, but #36 gets us updates, which is more trés sexy.

@wsanchez wsanchez modified the milestones: Later, Burning Man 2016 Aug 13, 2016
@wsanchez wsanchez removed their assignment Aug 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant