1
0
mirror of https://github.com/osmarks/website synced 2024-12-24 00:50:31 +00:00

fix achievement system for new users

This commit is contained in:
osmarks 2022-03-11 16:12:25 +00:00
parent d8ee33cd78
commit d0feda98e1

View File

@ -154,27 +154,33 @@ window.points = (async () => {
} }
} }
const [oldMetrics, oldPoints] = await Promise.all([idb.openDB("arbitrary-metrics"), idb.openDB("arbitrary-points")]) let [metrics, pointsData] = [{}, {}]
const getMetrics = async () => { try {
const metrics = {} const [oldMetrics, oldPoints] = await Promise.all([idb.openDB("arbitrary-metrics"), idb.openDB("arbitrary-points")])
const tx = oldMetrics.transaction("metrics", "readonly") const getMetrics = async () => {
for (const key of await tx.store.getAllKeys()) { const metrics = {}
metrics[key] = await tx.store.get(key) const tx = oldMetrics.transaction("metrics", "readonly")
for (const key of await tx.store.getAllKeys()) {
metrics[key] = await tx.store.get(key)
}
return metrics
} }
return metrics const getPointsData = async () => {
} const data = {}
const getPointsData = async () => { const tx = oldPoints.transaction("data", "readonly")
const data = {} for (const key of await tx.store.getAllKeys()) {
const tx = oldPoints.transaction("data", "readonly") data[key] = await tx.store.get(key)
for (const key of await tx.store.getAllKeys()) { }
data[key] = await tx.store.get(key) return data
} }
return data [metrics, pointsData] = await Promise.all([getMetrics(), getPointsData()])
await Promise.all([oldMetrics.close(), oldPoints.close()])
} catch(e) {
console.warn("old achievements not loaded due to", e)
} }
const [metrics, pointsData] = await Promise.all([getMetrics(), getPointsData()])
await Promise.all([oldMetrics.close(), oldPoints.close()])
const db = await idb.openDB("arbitrary-data", 1, { const db = await idb.openDB("arbitrary-data", 1, {
async upgrade(db, oldVersion, newVersion, tx) { async upgrade(db, oldVersion, newVersion, tx) {
console.log("migrating", oldVersion, newVersion)
if (!oldVersion || oldVersion < 1) { if (!oldVersion || oldVersion < 1) {
// create metrics, KV, achievements stores // create metrics, KV, achievements stores
db.createObjectStore("kv") db.createObjectStore("kv")