qpixel icon indicating copy to clipboard operation
qpixel copied to clipboard

User filters are fetched redundantly

Open trichoplax opened this issue 2 years ago • 2 comments

Describe the bug Due to a correctness fix in #1079 the user filters in localStorage are no longer used, with the user filters being fetched from the server every time. This means the behaviour is now correct, but slower.

Going back to accessing the user filters from localStorage will cause the same bug again (changes do not show up on a different device) unless we add some kind of cache invalidation for localStorage.

Expected behavior When user filters are needed, the browser checks in localStorage. If the data in localStorage is up to date, the browser uses it. Otherwise, the browser makes a request to fetch the up to date data from the server, and overwrites the outdated data in localStorage.

trichoplax avatar Jun 22 '23 12:06 trichoplax

Possible solution

We could store a hash of the user filters in the user filters object, which will mean it is automatically stored both serverside and clientside (in localStorage). Then we can serve the hash in the HTML and reload the user filters from the server when the hashes in the HTML and localStorage do not match.

So on the client, instead of a JS object

user_filters: {
    filter_1: stuff,
    filter_2: more_stuff
}

We could have

user_filters: {
    hash: "NNNNN",
    filters: {
        filter_1: stuff,
        filter_2: more_stuff
    }
}

Where NNNNN is the hash of

filters: {
    filter_1: stuff,
    filter_2: more_stuff
}

trichoplax avatar Jun 22 '23 13:06 trichoplax

See Discord discussion pointing out that a hash is not necessary as we can use the last update datetime: https://discord.com/channels/634104110131445811/635510793961472020/1127623991792779375

trichoplax avatar Jul 09 '23 16:07 trichoplax