Javascript IndexedDB为简单对象占用大量空间
Im存储一个JSON对象,包括IndexedDB中的18个图像-每个图像最多50KB,但不知怎的,IndexedDB中需要118MB我不知道它为什么这么重 除了图像,它都是纯JSON,大部分是带有文本的键/值对 请参阅附加的屏幕截图 我正在使用DexieJS处理IndexedDB 保存到数据库的函数如下所示:Javascript IndexedDB为简单对象占用大量空间,javascript,ecmascript-6,indexeddb,dexie,Javascript,Ecmascript 6,Indexeddb,Dexie,Im存储一个JSON对象,包括IndexedDB中的18个图像-每个图像最多50KB,但不知怎的,IndexedDB中需要118MB我不知道它为什么这么重 除了图像,它都是纯JSON,大部分是带有文本的键/值对 请参阅附加的屏幕截图 我正在使用DexieJS处理IndexedDB 保存到数据库的函数如下所示: export const savePendingSurvey = (id, currentSurvey, surveyAnswers, surveyFiles) => { c
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://在Dexie问题和中有类似的问题。IndexedDB的大多数实现似乎与大多数数据库一样——它为每次更新添加新行,并标记旧版本以供以后删除。当数据库达到一定大小时,它将对旧行进行垃圾收集。有没有办法保持较小的数据库大小,或者它只是“自动”发生?@nickycdk没有据我所知,不幸的是没有API来控制这一点。