Skip to content

Commit d4ddb0e

Browse files
author
robot
committed
feat: 每天全量更新一次
1 parent 82ff904 commit d4ddb0e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

middleware/mockUserInfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module.exports = ({ whitelist = [] }) =>
44
ctx.session = {};
55
}
66
ctx.session.user = {
7-
login: "lilyzhaoyilu",
8-
// login: "YanFaFa",
7+
// login: "lilyzhaoyilu",
8+
login: "YanFaFa",
99
// login: "shuo0314",
1010
// login: "azl397985856",
1111
avatar_url: "https://avatars.githubusercontent.com/u/12479470?v=4",

schedule/daily-check.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { owner, repo } = require("../config/index");
66

77
const solutions = require("../static/solution/solutions.json");
88
const mySolutions = require("../static/my/solutions.json");
9+
const { get } = require("http");
910

1011
const octokit = new Octokit({ auth: process.env.issueToken });
1112
function getAllPages(i, issue_number) {
@@ -46,6 +47,9 @@ async function run(d) {
4647
onTime: getDay(new Date(comment.created_at).getTime()) <= d,
4748
};
4849
});
50+
mySolutions["_meta_"] = {
51+
lastUpdateTime = new Date().getTime()
52+
}
4953
fs.writeFileSync(
5054
path.resolve(__dirname, "../static/my/solutions.json"),
5155
JSON.stringify(mySolutions)
@@ -55,9 +59,17 @@ async function run(d) {
5559
const MS_PER_HOUR = 1 * 60 * 60 * 1000;
5660
const TODAY = getDay(new Date().getTime() - MS_PER_HOUR); // 获取今天‘的题目。 为了照顾一些人, 我们凌晨一点统计昨天的,而不是当天的。
5761

62+
// 仅更新当天的
63+
if (getDay(TODAT) - getDay(mySolutions["__meta__"].lastUpdateTime) < 1) {
64+
run(TODAY)
65+
} else {
66+
// 更新历史所有的,每天仅全量更新一次
5867
// 1. 记录打卡数据
5968
// 2. 修正之前的数据错误
6069
// 3. 登记补卡信息
6170
for (let d = 1; d <= TODAY; d++) {
6271
run(d);
6372
}
73+
}
74+
75+

0 commit comments

Comments
 (0)