Optimise thumbnail database upgrade
This commit is contained in:
parent
9dbd7e35a6
commit
1e0489d452
@ -9,7 +9,12 @@ import { createThumbnail } from "./helpers/image";
|
|||||||
|
|
||||||
// Helper to create a thumbnail for a file in a db
|
// Helper to create a thumbnail for a file in a db
|
||||||
async function createDataThumbnail(data) {
|
async function createDataThumbnail(data) {
|
||||||
const url = URL.createObjectURL(new Blob([data.file]));
|
let url;
|
||||||
|
if (data?.resolutions?.low?.file) {
|
||||||
|
url = URL.createObjectURL(new Blob([data.resolutions.low.file]));
|
||||||
|
} else {
|
||||||
|
url = URL.createObjectURL(new Blob([data.file]));
|
||||||
|
}
|
||||||
return await Dexie.waitFor(
|
return await Dexie.waitFor(
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
let image = new Image();
|
let image = new Image();
|
||||||
@ -363,11 +368,15 @@ const versions = {
|
|||||||
// 1.8.0 - Add thumbnail to maps and add measurement to grid
|
// 1.8.0 - Add thumbnail to maps and add measurement to grid
|
||||||
19(v) {
|
19(v) {
|
||||||
v.stores({}).upgrade(async (tx) => {
|
v.stores({}).upgrade(async (tx) => {
|
||||||
|
const userId = (await Dexie.waitFor(tx.table("user").get("userId")))
|
||||||
|
.value;
|
||||||
const maps = await Dexie.waitFor(tx.table("maps").toArray());
|
const maps = await Dexie.waitFor(tx.table("maps").toArray());
|
||||||
const thumbnails = {};
|
const thumbnails = {};
|
||||||
for (let map of maps) {
|
for (let map of maps) {
|
||||||
try {
|
try {
|
||||||
thumbnails[map.id] = await createDataThumbnail(map);
|
if (map.owner === userId) {
|
||||||
|
thumbnails[map.id] = await createDataThumbnail(map);
|
||||||
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
return tx
|
return tx
|
||||||
@ -382,11 +391,15 @@ const versions = {
|
|||||||
// 1.8.0 - Add thumbnail to tokens
|
// 1.8.0 - Add thumbnail to tokens
|
||||||
20(v) {
|
20(v) {
|
||||||
v.stores({}).upgrade(async (tx) => {
|
v.stores({}).upgrade(async (tx) => {
|
||||||
|
const userId = (await Dexie.waitFor(tx.table("user").get("userId")))
|
||||||
|
.value;
|
||||||
const tokens = await Dexie.waitFor(tx.table("tokens").toArray());
|
const tokens = await Dexie.waitFor(tx.table("tokens").toArray());
|
||||||
const thumbnails = {};
|
const thumbnails = {};
|
||||||
for (let token of tokens) {
|
for (let token of tokens) {
|
||||||
try {
|
try {
|
||||||
thumbnails[token.id] = await createDataThumbnail(token);
|
if (token.owner === userId) {
|
||||||
|
thumbnails[token.id] = await createDataThumbnail(token);
|
||||||
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
return tx
|
return tx
|
||||||
|
Loading…
Reference in New Issue
Block a user