Fix IndexedDBCache getInverseRelationshipsAsync #823
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
馃挜 Important: Action is needed to update pre-existing
@orbit/indexeddb
databases. See below. 馃挜This PR fixes an issue with
IndexedDBCache#getInverseRelationshipsAsync
in which the wrong index was being used to lookup items in the object store that maintains inverse relationships (__inverseRels__
). This issue may have prevented theAsyncCacheIntegrityProcessor
from properly removing relationships when records were removed. Therefore, it's possible that your cache may contain extra "dead" relationships (i.e. relationships to records that have been removed).This PR adds the missing index,
relatedIdentity
, to the object store__inverseRels__
when it is created. Therefore, any new IndexedDB databases should now properly track inverse relationships.Has this bug affected my data?
This bug appears to only affect the integrity of relationships which do not have matching inverses explicitly declared.
In the following schema, inverse relationships are explicitly declared:
The integrity of
planet.moons
andmoon.planet
will have been maintained when either a moon or planet is removed. If all your relationships have explicit inverses declared like this, then your IndexedDB data should not be affected by this bug.However, in the following scenario, the relationship is one-sided, without an inverse:
In this case, deleting a moon will not have resulted in the moon being cleared from any planets that contained that moon in their
moons
relationship. You may wish to validate your relationship data as part of the following steps.Recreating / migrating pre-existing databases
If your application has any pre-existing IndexedDB databases "in the wild", you'll need to take steps to update them. The steps you take really depend why / how you're using this source in your app. If you're just using it as a temporary offline buffer, you may choose to just drop and recreate the database. However, if your IndexedDB source is the "source of truth" for some of your application's data, you'll want to upgrade the database and validate its data if it may have been affected (see above).
In order to perform an upgrade, take the following steps:
version
of yourSchema
.migrateDB
method for your cache instance. Ifevent.newVersion
equals your new schema version, modify the__inverseRels__
object store to add therelatedIdentity
index.__inverseRels__
withinmigrateDB
, pruning any references to non-existent records.For example, let's say that you set the new schema
version
to2
. OverridemigrateDB
as follows:Please comment here or reach out on gitter if you have questions or problems.