resourceloader: Purge localStorage blob if last written 30+ days ago
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 6 Aug 2019 00:12:39 +0000 (01:12 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 27 Aug 2019 20:28:53 +0000 (20:28 +0000)
commit2d70c46b0f947505cdffdd5da5492cc9b2c482a6
treedc7a67b39df31ecc477316770e501efe576a18f5
parent51cc4c3d67f9b8cbd08856a46bacd49580286784
resourceloader: Purge localStorage blob if last written 30+ days ago

Our version hashes are 6-7 chars of base36 from a fnv132 digest.
Using the formula of <https://en.wikipedia.org/wiki/Birthday_attack>
that provides enough range to publish 2087 different versions of
a given module before there is a 0.1% probability to clash with
another version, 660 versions for a 0.01% probability, and
209 versions of a 0.001% probability.

I think 200 versions of a single module is a good enough space
for most use cases we have of the version hash (such as the E-Tag
header for browser caches and HTTP proxies, whic have have a 30-day
TTL).

However, for mw.loader.store it's a bit tricky. It's generally
more than enough given that (unlike HTTP caches) we only store
1 version of any given module so we don't need it to be different
from N different versions, just the last one.

But, also unlike HTTP caches, localStorage has no expiry. This means
that while for a single user it only has to be different from their
last-seen version, but from the server perspective, it needs to be
different from all possible versions a given user may have last seen.
This is problematic and effectively unbounded.

Plug this hole by discarding the localStorage value and starting
fresh, if the user last visited the site more than 30 days ago.

This is also in preparation for T229245, which will reduce the
hash from 6-7 chars to 5 chars. With that size, we can support only
348 different versions at a 0.1% probability (instead of 2087).
Which is fine for the bounded use cases with a TTL, but would make
the unbounded nature of localStorage even more problematic.

Bug: T229245
Change-Id: Iba8cdbebf1bb5c7c628832708fd656fcef61c095
resources/src/startup/mediawiki.js
tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js