MCPcopy Index your code
hub / github.com/hydro-dev/Hydro / runInDomain

Function runInDomain

packages/hydrooj/src/script/rating.ts:139–162  ·  view source on GitHub ↗
(domainId: string, report: Report)

Source from the content-addressed store, hash-verified

137}
138
139async function runInDomain(domainId: string, report: Report) {
140 const results: Record<keyof typeof RpTypes, ND> = {};
141 const udict = Counter();
142 await db.collection('domain.user').updateMany({ domainId }, { $set: { rpInfo: {} } });
143 for (const type in RpTypes) {
144 results[type] = new Proxy({}, { get: (self, key) => self[key] || RpTypes[type].base });
145 await RpTypes[type].run([domainId], results[type], report);
146 const bulk = db.collection('domain.user').initializeUnorderedBulkOp();
147 for (const uid in results[type]) {
148 const udoc = await UserModel.getById(domainId, +uid);
149 if (!udoc?.hasPriv(PRIV.PRIV_USER_PROFILE)) continue;
150 bulk.find({ domainId, uid: +uid }).updateOne({ $set: { [`rpInfo.${type}`]: results[type][uid] } });
151 udict[+uid] += results[type][uid];
152 }
153 if (bulk.batches.length) await bulk.execute();
154 }
155 await domain.setMultiUserInDomain(domainId, {}, { rp: 0 });
156 const bulk = db.collection('domain.user').initializeUnorderedBulkOp();
157 for (const uid in udict) {
158 bulk.find({ domainId, uid: +uid }).upsert().update({ $set: { rp: Math.max(0, udict[uid]) } });
159 }
160 if (bulk.batches.length) await bulk.execute();
161 await calcLevel(domainId, report);
162}
163
164export async function run({ domainId }, report: Report) {
165 if (!domainId) {

Callers 1

runFunction · 0.85

Calls 10

CounterFunction · 0.90
calcLevelFunction · 0.85
collectionMethod · 0.80
getByIdMethod · 0.80
hasPrivMethod · 0.80
findMethod · 0.80
executeMethod · 0.80
setMultiUserInDomainMethod · 0.80
runMethod · 0.65
updateMethod · 0.45

Tested by

no test coverage detected