IndexedDB 为简单对象占用大量 space
IndexedDB taking up a lot of space for simple object
我正在存储一个 JSON 对象,包括 IndexedDB 中的 18 个图像 - 每个图像最多 50KB,但不知何故它在 indexedDB 中占用 118MB? - 我不知道为什么这么重?
除了图片,一切都很普通JSON,大部分key/value与文字成对...
见附件截图
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 :/
我正在存储一个 JSON 对象,包括 IndexedDB 中的 18 个图像 - 每个图像最多 50KB,但不知何故它在 indexedDB 中占用 118MB? - 我不知道为什么这么重?
除了图片,一切都很普通JSON,大部分key/value与文字成对...
见附件截图
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 :/