mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-30 00:13:06 +00:00
Better memory usage
This commit is contained in:
parent
68cf16882f
commit
b2a2f98d6a
1 changed files with 25 additions and 5 deletions
|
@ -42,10 +42,30 @@ const migrateToGridFS = async (doc) => {
|
||||||
return added && result.ok === 1
|
return added && result.ok === 1
|
||||||
}
|
}
|
||||||
|
|
||||||
const main = async () => {
|
async function main() {
|
||||||
const docs = await db.get('drive_files').find()
|
let i = 0;
|
||||||
const all = await Promise.all(docs.map(migrateToGridFS))
|
|
||||||
return all
|
const count = db.get('drive_files').count;
|
||||||
|
|
||||||
|
const iterate = async () => {
|
||||||
|
if (i == count) return true;
|
||||||
|
const doc = await db.get('drive_files').find({}, { skip: i })
|
||||||
|
const res = await migrateToGridFS(doc);
|
||||||
|
if (!res) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
i++
|
||||||
|
return await iterate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await iterate();
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
return 'ok';
|
||||||
|
} else {
|
||||||
|
throw 'something happened';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main().then(console.dir).catch(console.error)
|
main().then(console.dir).catch(console.error)
|
||||||
|
|
Loading…
Reference in a new issue