You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most of the time, you can do this more efficiently by using optimistic writes. If you set your store to use versions, you can do this, which will only increment the integer if it hasn't changed (otherwise it will try again), guaranteeing atomic incrementation:
let success;
do {
let { value, version } = db.getEntry(key);
success = await db.ifVersion(key, version, () => db.put(key, int + 1, version + 1);
} while(!success);
It is possible that this can be result in multiple iterations inhighly write contention situations, but usually this is a good technique (if it rarely retries). And it may be nice to provide a low-level incrementation, but generally these primitives work well across a pretty broad range of scenarios.
Hello,
I would like to inquiry on the best ways to increment an integer, is there any way more efficient than this?
The above method has a pretty large performance penalty for such a simple operation.
If there isn't any better way, I would like to inquire about adding methods for efficient incrementation of numerical values.
Thanks!
The text was updated successfully, but these errors were encountered: