From 706e1183a9d3ce2de9164bb9a45eeccce5053014 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Fri, 13 Aug 2021 09:47:35 -0700 Subject: [PATCH] perf: use IDBObjectStore.clear --- src/database/idbInterface.js | 14 +++----------- src/database/idbUtil.js | 4 ---- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/database/idbInterface.js b/src/database/idbInterface.js index 6201f224..bcd177ce 100644 --- a/src/database/idbInterface.js +++ b/src/database/idbInterface.js @@ -8,7 +8,7 @@ import { } from './constants' import { transformEmojiData } from './utils/transformEmojiData' import { extractTokens } from './utils/extractTokens' -import { getAllIDB, getAllKeysIDB, getIDB } from './idbUtil' +import { getAllIDB, getIDB } from './idbUtil' import { findCommonMembers } from './utils/findCommonMembers' import { normalizeTokens } from './utils/normalizeTokens' @@ -67,11 +67,10 @@ export async function loadData (db, emojiData, url, eTag) { await dbPromise(db, [STORE_EMOJI, STORE_KEYVALUE], MODE_READWRITE, ([emojiStore, metaStore]) => { let oldETag let oldUrl - let oldKeys let todo = 0 function checkFetched () { - if (++todo === 3) { + if (++todo === 2) { // 2 requests made onFetched() } } @@ -82,9 +81,7 @@ export async function loadData (db, emojiData, url, eTag) { return } // delete old data - for (const key of oldKeys) { - emojiStore.delete(key) - } + emojiStore.clear() // insert new data for (const data of transformedData) { emojiStore.put(data) @@ -103,11 +100,6 @@ export async function loadData (db, emojiData, url, eTag) { oldUrl = result checkFetched() }) - - getAllKeysIDB(emojiStore, undefined, result => { - oldKeys = result - checkFetched() - }) }) performance.measure('commitAllData', 'commitAllData') } finally { diff --git a/src/database/idbUtil.js b/src/database/idbUtil.js index 8643ebd3..2d35c075 100644 --- a/src/database/idbUtil.js +++ b/src/database/idbUtil.js @@ -11,7 +11,3 @@ export function getIDB (store, key, cb) { export function getAllIDB (store, key, cb) { callStore(store, 'getAll', key, cb) } - -export function getAllKeysIDB (store, key, cb) { - callStore(store, 'getAllKeys', key, cb) -}