Commit Graph

19 Commits

Author SHA1 Message Date
Ben Newman
36d9bc12bb Fix a few Object.prototype.hasOwnProperty misuses.
As reported by @leosco:
https://github.com/meteor/meteor/pull/9942#issuecomment-411902381
2018-08-09 18:19:35 -04:00
Ben Newman
29f2509a46 Fix small typo in dynamic-import/cache.js. 2017-09-15 13:29:42 -04:00
Ben Newman
e3bd1cfb9c Make dynamic import(...) caching more robust to IndexedDB failures.
Fixes #8697.
2017-05-15 12:11:30 -04:00
Ben Newman
f4fc2a904d Use final hashes of dynamic modules for browser caching.
Previously, the linker included a "version" hash in each stub entry
corresponding to a dynamic module in the meteorInstall bundle. These stub
entries also contain information about any module identifiers ("deps")
imported by the module, and various other metadata.

This hash was derived from the source code of the dynamic module, instead
of its fully-processed generated code, which created a small risk that the
source hash would remain the same when anything changed in the post-linker
processing logic.

This new implementation uses the same hashes found in program.json
manifest files, which more reliably reflect changes in the actual final
contents of the modules.

Because these hashes are not known at link time, they are now injected as
one blob into the meteor/dynamic-import/dynamic-versions.js module, rather
than appearing in the meteorInstall bundles for their containing packages.
2017-04-21 16:15:09 -04:00
Ben Newman
337a61c426 Disable dynamic module fetching in Cordova apps.
Instead of fetching a bundle of JavaScript from the server, Cordova apps
include the complete bundle in the installed app, so there's no compelling
reason to allow dynamic module fetching.

The dynamic import(...) function will still work on Cordova, of course.
It will just never have to fetch anything from the server.
2017-04-04 19:09:26 -04:00
Ben Newman
ec3341e7ad Inline put(store, object) helper function since used only once. 2017-03-08 14:58:35 -05:00
Ben Newman
52c6c99b4d Remove versionsById IndexedDB object store.
Keeping track of the latest version for each module identifier was more
important when we were using localStorage, because it helped with
periodically removing unused module sources.

Since the storage limits for IndexedDB are substantially higher than for
localStorage, we can safely keep old versions in the cache, and reap the
benefits if those versions are ever needed again.

Eliminating this extra logic simplifies the caching logic considerably,
and also improves cache read performance.
2017-03-07 18:18:05 -05:00
Ben Newman
8c44044cd1 Ensure checkCount is decremented even if individual checks fail. 2017-03-07 18:14:37 -05:00
Ben Newman
23e82bb1ef Include more error information when IndexedDB operations fail. 2017-03-07 16:43:54 -05:00
Ben Newman
732915c9a2 Revert "Share cache.checkMany transaction between simultaneous calls."
This reverts commit 027d3e15a7.

This optimization was not safe in all browsers. In particular, Firefox
complained about requests against inactive transactions.
2017-03-06 21:30:36 -05:00
Ben Newman
2071bdd820 Fix tests by throwing real Error objects when IndexedDB fails. 2017-03-06 20:48:54 -05:00
Ben Newman
b0a5bd51f1 Fix tests by rejecting proper Error objects. 2017-03-04 20:56:07 -05:00
Ben Newman
4225528646 Try harder to find the indexedDB API object. 2017-03-04 20:56:00 -05:00
Ben Newman
027d3e15a7 Share cache.checkMany transaction between simultaneous calls.
If import(...) is called multiple times in quick succession, these changes
should allow cache.checkMany to avoid the overhead of creating multiple
IndexedDB transactions.
2017-03-04 19:56:11 -05:00
Ben Newman
eb33152ce3 Prevent IndexedDB from auto-committing too early.
Discussion: https://twitter.com/benjamn/status/838108246841917441
2017-03-04 19:56:11 -05:00
Ben Newman
e8f224638c Postpone cache.setMany if cache.checkMany currently underway. 2017-03-04 19:00:32 -05:00
Ben Newman
afb7e31c51 Use IndexedDB instead of localStorage for caching dynamic modules.
I was able to achieve tolerable performance by using only one (read-only)
transaction for each cache.getMany call, and only one (read+write)
transaction for each cache.setMany call.
2017-03-04 19:00:31 -05:00
Ben Newman
51c9f5e16c Use Meteor._localStorage only in production mode.
https://github.com/meteor/meteor/pull/8327#issuecomment-278660587
2017-02-09 10:19:24 -05:00
Ben Newman
7c5f8789ed Enable immutable caching for dynamic modules.
Even though localStorage is a synchronous API, I wrote this code in an
asynchronous style so that we can easily switch to an async API when/if
that becomes preferable.

While localStorage has stricter size limits than IndexedDB, retrieving
data from IndexedDB is unbelievably slow (~10ms for each cache.check
call). When developing locally, that delay pretty much destroys any
benefit from caching.
2017-02-07 16:17:44 -05:00