【发布时间】:2020-03-14 02:49:29
【问题描述】:
我存储一个 JSON 对象,包括 IndexedDB 中的 18 个图像 - 每个图像最多 50KB,但不知何故它需要 118 MB 在 indexedDB 中? - 不知道为什么这么重?
除了图像之外,它都是纯 JSON,主要是带有文本的键/值对...
查看附件截图
我正在使用 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