[英]IndexedDB: Uncaught (in promise) DOMException
I am using indexedDB(via npm's idb wrapper) to store 2D Float32 arrays which represent audio channel data.我正在使用 indexedDB(通过 npm 的 idb 包装器)来存储表示音频通道数据的 2D Float32 数组。 It works fine for some time, however, when the length of one of the arrays reaches approximately
16658432
, idb crashes with the exception in the title.它可以正常工作一段时间,但是,当其中一个数组的长度达到大约
16658432
, 16658432
崩溃,标题中出现异常。 Stack trace is pretty useless as I am using React in conjunction with Next.js, however from what I dag out, it appears it crashes at idb's caching part.堆栈跟踪非常无用,因为我将 React 与 Next.js 结合使用,但是从我发现的情况来看,它似乎在 idb 的缓存部分崩溃了。 Note: I can store multiple large arrays no problem, but everything breaks once either of them exceeds this "limit"
注意:我可以存储多个大数组没问题,但是一旦它们中的任何一个超过此“限制”,一切都会中断
Is this a limitation I just have to deal with, or can this be worked around in some way?这是我必须处理的限制,还是可以以某种方式解决? I could potentially split the 2D array into two arrays and store them as separate entries, but this is a less than ideal solution, which will cause the same problem once they grow too.
我可以将二维数组分成两个数组并将它们存储为单独的条目,但这是一个不太理想的解决方案,一旦它们增长也会导致同样的问题。
Just a simple wrapper around idb's transactions:只是围绕 idb 交易的一个简单包装:
export const asyncPut = async (
dbName: string,
tableName: string,
key: string,
value: any // [Float32Array, Float32Array]
): Promise<void> => {
try {
const db = await asyncOpenDb(dbName, tableName);
const transaction = db.transaction(tableName, "readwrite");
await transaction.objectStore(tableName).put(value, key);
} catch (error) {
// I catch the error here
console.error("**IDB Error:", error);
}
};
I just tested this in Chrome and they might have improved the errors since you've tested.我刚刚在 Chrome 中对此进行了测试,自从您进行测试后,他们可能已经改善了错误。
The error that I'm getting when I tried to insert this array:尝试插入此数组时遇到的错误:
ar = new Array(16658432).fill(1)
is that it exceeds the max size of a single object:是它超过了单个对象的最大大小:
target: IDBRequest
error: DOMException
code: 0
message: "The serialized keys and/or value are too large (size=515354750 bytes, max=133169152 bytes)."
name: "UnknownError"
__proto__: DOMException
Tested in:测试于:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.