Browse Source

Update discussion data in admin panel

master
Pisces000221 7 years ago
parent
commit
f360508382
  1. 13
      models/article.js
  2. 5
      modules/admin.js
  3. 3
      views/admin_other.ejs

13
models/article.js

@ -91,6 +91,19 @@ class Article extends Model {
return user && (this.allow_comment || user.is_admin || this.user_id === user.id); return user && (this.allow_comment || user.is_admin || this.user_id === user.id);
} }
async resetReplyCountAndTime() {
let ArticleComment = syzoj.model('article-comment');
await syzoj.utils.lock(['Article::resetReplyCountAndTime', this.id], async () => {
this.comments_num = await ArticleComment.count({ article_id: this.id });
if (this.comments_num === 0) {
this.sort_time = this.public_time;
} else {
this.sort_time = await ArticleComment.model.max('public_time', { where: { article_id: this.id } });
}
await this.save();
});
}
getModel() { return model; } getModel() { return model; }
}; };

5
modules/admin.js

@ -320,6 +320,11 @@ app.post('/admin/other', async (req, res) => {
for (const p of problems) { for (const p of problems) {
await p.resetSubmissionCount(); await p.resetSubmissionCount();
} }
} else if (req.body.type === 'reset_discussion') {
const articles = await Article.query();
for (const a of articles) {
await a.resetReplyCountAndTime();
}
} else { } else {
throw new ErrorMessage("操作类型不正确"); throw new ErrorMessage("操作类型不正确");
} }

3
views/admin_other.ejs

@ -1,7 +1,8 @@
<% this.adminPage = 'other'; %> <% this.adminPage = 'other'; %>
<% include admin_header %> <% include admin_header %>
<form method="post" class="ui form"> <form method="post" class="ui form">
<button class="ui blue button" name="type" value="reset_count" type="submit">重新计算提交及 AC 数</button> <p><button class="ui blue button" name="type" value="reset_count" type="submit">重新计算提交及 AC 数</button></p>
<p><button class="ui blue button" name="type" value="reset_discussion" type="submit">重新计算讨论版回复数和回复时间</button></p>
<!-- <button name="type" value="reset_size" type="submit">重新计算代码大小</button> --> <!-- <button name="type" value="reset_size" type="submit">重新计算代码大小</button> -->
</form> </form>
<% include admin_footer %> <% include admin_footer %>

Loading…
Cancel
Save