mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 01:38:19 +08:00
core: feat: allow star problem
This commit is contained in:
1 parent
f7f977293c
commit
ef32ee3865
8 files changed
+63
-4
No files matched your search
@@ -95,6 +95,21 @@ class HomeHandler extends Handler {
|
||||
return ['ranking', []];
|
||||
}
|
||||
|
||||
async getStarredProblem(domainId: string, limit = 50) {
|
||||
if (this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) {
|
||||
const psdocs = await ProblemModel.getMultiStatus(domainId, { uid: this.user._id, star: true })
|
||||
.sort('_id', 1).limit(limit).toArray();
|
||||
const psdict = {};
|
||||
for (const psdoc of psdocs) psdict[psdoc.docId] = psdoc;
|
||||
const pdict = await ProblemModel.getList(
|
||||
domainId, psdocs.map((pdoc) => pdoc.docId), false,
|
||||
);
|
||||
const pdocs = Object.keys(pdict).filter((i) => +i).map((i) => pdict[i]);
|
||||
return ['problem', pdocs, psdict];
|
||||
}
|
||||
return ['problem', [], {}];
|
||||
}
|
||||
|
||||
async get({ domainId }) {
|
||||
const homepageConfig = system.get('hydrooj.homepage');
|
||||
const tasks = [];
|
||||
@@ -104,6 +119,7 @@ class HomeHandler extends Handler {
|
||||
if (!this[func]) continue;
|
||||
tasks.push(this[func](domainId, +info[key]));
|
||||
}
|
||||
const [, pdocs, psdict] = await this.getStarredProblem(domainId);
|
||||
const contents = await Promise.all(tasks);
|
||||
const [udict, dodoc, vnodes] = await Promise.all([
|
||||
user.getList(domainId, Array.from(this.uids)),
|
||||
@@ -116,6 +132,8 @@ class HomeHandler extends Handler {
|
||||
udict,
|
||||
domain: dodoc,
|
||||
vnodes,
|
||||
pdocs,
|
||||
psdict,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user