mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
自动释放锁,优化record.getList()
This commit is contained in:
1 parent
d3deeaeb96
commit
2bf6adbaa0
12 files changed
+51
-28
No files matched your search
@@ -200,11 +200,10 @@ export function getNodes(domainId: string) {
|
||||
export async function getListVnodes(domainId: string, ddocs: any, handler: any) {
|
||||
const tasks = [];
|
||||
const res = {};
|
||||
function task(ddoc) {
|
||||
return getVnode(domainId, ddoc, handler).then((vnode) => {
|
||||
if (!res[ddoc.parentType]) res[ddoc.parentType] = {};
|
||||
res[ddoc.parentType][ddoc.parentId] = vnode;
|
||||
});
|
||||
async function task(ddoc) {
|
||||
const vnode = await getVnode(domainId, ddoc, handler);
|
||||
if (!res[ddoc.parentType]) res[ddoc.parentType] = {};
|
||||
res[ddoc.parentType][ddoc.parentId] = vnode;
|
||||
}
|
||||
for (const ddoc of ddocs) tasks.push(task(ddoc));
|
||||
await Promise.all(tasks);
|
||||
|
||||
@@ -140,14 +140,14 @@ export function count(domainId: string, query: any) {
|
||||
}
|
||||
|
||||
export async function getList(
|
||||
domainId: string, rids: ObjectID[], showHidden = false,
|
||||
domainId: string, rids: ObjectID[], showHidden: boolean,
|
||||
): Promise<Dictionary<Rdoc>> {
|
||||
const r = {};
|
||||
for (const rid of rids) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const rdoc = await get(domainId, rid);
|
||||
if (rdoc.hidden && !showHidden) r[rid.toHexString()] = null;
|
||||
else r[rid.toHexString()] = rdoc;
|
||||
rids = Array.from(new Set(rids));
|
||||
const rdocs = await coll.find({ domainId, _id: { $in: rids } }).toArray();
|
||||
for (const rdoc of rdocs) {
|
||||
if (rdoc.hidden && !showHidden) r[rdoc._id.toHexString()] = null;
|
||||
else r[rdoc._id.toHexString()] = rdoc;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user