IndexedDB为简单对象占用了大量空间

问题描述 投票:0回答:1

我正在存储一个JSON对象,其中在IndexedDB中包含18张图像-每个图像最大为50KB,但是以某种方式在indexedDB中需要118 MB? -我不知道为什么这么重?

除了图像,全部都是纯JSON,主要是带有文本的键/值对...

请参阅附件的屏幕截图

Size of indexedDB

Item in IndexedDB

我正在使用DexieJS来处理IndexedDB

正在保存到数据库的函数如下:

  export const savePendingSurvey = (id, currentSurvey, surveyAnswers, surveyFiles) => {
const updatedSurvey = {
    id: id,
    createdAt: new Date(),
    status: 'UNSUBMITTED',
    surveyVersion: currentSurvey.survey.version,
    currentSurvey: {
        ...currentSurvey.survey
    },
    currentSurveyAnswers: [
        ...surveyAnswers
    ],
    currentSurveyFiles: [
        ...surveyFiles
    ]
};

db.open().then(() => {
    db.pendingSurveys.put(updatedSurvey).then((response) => {
        console.log('done adding pending survey', response);
    }).then(() => {
        return db.pendingSurveys.toArray();
    }).then((data) => {
        console.log('pendings surveys in db', data);
    }).catch((e) => {
        if ((e.name === 'QuotaExceededError') ||
            (e.inner && e.inner.name === 'QuotaExceededError')) {
            // QuotaExceededError may occur as the inner error of an AbortError
            alert('QuotaExceeded error! - There are not enough space available on your device');
        } else {
            // Any other error
            console.error(e);
        }
    });
});
};

[似乎每次我对对象进行最简单的更新,即使更改了简单的文本,每次都会在项目之间添加100-300kbs:/

javascript ecmascript-6 indexeddb dexie
1个回答
0
投票

Dexie问题604641中也有类似的问题。似乎大多数IndexedDB的实现都像大多数数据库一样-它为每次更新添加新行,并将旧版本标记为以后删除。当数据库达到一定大小时,它将垃圾收集旧行。

© www.soinside.com 2019 - 2024. All rights reserved.