javascript - An efficient way of removing objects from an indexedDB object store that are missing a property -
i thinking how make operation in project of mine more efficient. operation in current implementation loads objects object store, iterates through array , testing whether object missing property or if property undefined, collecting set of such objects in second array, , removing of these objects.
i using getall obvious performance benefit on cursor iteration.
i concurrently calling individual delete requests, there no speed there the indexeddb api evolving support batch deletes on non-indexed non-keypath props missing values.
the issue have no way of checking against property when property not in keypath of object store without loading each object memory. objects rather large in cases. 1 of properties of each object extremely large (essentially string of html document).
i cannot use index, because properties not present in objects, or not have value, not appear in index.
is there way avoid loading such objects memory?
i have thought partitioning, , using 2 object stores, 1 queryable props , 1 full data. devolves having requests every read. app lot more reading occasional batch delete operation.
i have thought storing property per object has value myobject.doesotherpropertyhavevalue
contains 0/1 , therefore indexable, doesn't seem great either. sure query index , use getallkeys , solves problem. however, every add/put has maintain functional dependency.
any advice appreciated.
if records have form {key, prop}
prop 1 may not present, can create index on [key, prop]
. have index records when prop present. open 2 key-only cursors: 1 on store (c1) , 1 on index (c2). check see if c1.primarykey equals c2.primarykey[0]. if so, prop present, advance both. if keys not equal c1 points @ record doesn't have prop; delete , advance c1. repeat. (watch out edge cases when hit end of range.)
two problems this: (1) you're still using cursors, still paying cost of round trips (unlike getall()
), , (2) if prop large (i.e. body of html document mention) using key cursors you're still shuffling large amount of data around.
(in future we'd tackle adding either more general query mechanism or custom indexing possibly combined delete-on-index - either of make easier , more efficient)
...collecting set of such objects in second array, , removing of these objects...
if stick approach, remember can issue delete()
calls find them; no need collect objects, , don't need wait deletes finish; can use idb in "fire , forget" fashion write operations.
Comments
Post a Comment