Kinto / Kinto/kinto.js

IDB: use a multiEntry index and 'structured' keys

Open
#867 0 comments 0 reactions 0 assignees View on GitHub
stale
Dominant language
TypeScript
Stars
330
Forks
75
Avg merge
3d 5h
Merged PRs (30d)
4

Description

As suggested by Andrew in https://bugzilla.mozilla.org/show_bug.cgi?id=1486980#c36

Example pseudocode:
```js
objectStore.createIndex("app_indices", "appIndices", { multiEntry: true });

function fancyPut(idbDataStore, collectionName, collectionIndicesMap, appObj) {
const appIndices = collectionIndicies.map([indexName, indexEvalPath]) => {
// for the example, assume the key is not nested...
const appVal = appObj[indexEvalPath];
if (Array.isArray(appVal)) {
throw new Error("The value can't be an array for our current bounds cleverness.");
}
// Create an index key that's array-structured so we can bound its
// key-space.
return [collectionName, indexName, appVal];
});
const wrappedObj = {
actualObj: appObj
appIndices
};
return idbDataStore.put(wrappedObj);
}

async function findWithIndex(idbDataStore, collectionName, indexName, appExact,
[appLow, appHigh]) {
// [collectionName, indexName] lower-bounds all [collectionName, indexName, ...]
// because a shorter array is by definition less than a longer array that is
// equal up to their shared length.
// [collectionName, indexName, []] upper-bounds all [collectionName, indexName, ...]
// because arrays are always greater than strings/dates/numbers. So as long
// as the other contents of the index are non-arrays, we're good.
const wholeIndexBounds = IDBKeyRange.bound(
[collectionName, indexName],
[collectionName, indexName, []],
true, true); // exclusive range for the edge-case values.
const exactIndexBounds = IDBKeyRange.only([collectionName, indexName, appValue]);
const rangeBounds = IDBKeyRange.bound(
[collectionName, indexName, appLow],
[collectionName, indexName, appHigh],
false, false); // assume caller meant inclusive.
// DO ACTUAL INDEX STUFF
return wrappedObj.actualObj;
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the issue's IndexedDB entry points: createIndex, IDBKeyRange.bound, IDBKeyRange.only, and the datastore put and lookup operations shown in the pseudocode. Determine how multiEntry indexes and structured array keys should fit the existing client, then define completion through working exact and range index queries; no files or tests are identified in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.