Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use IDBObjectStore.clear #208

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/database/idbInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions src/database/idbUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}