Skip to content

Commit 71e9dce

Browse files
committed
refactor: add rand to gitlab data update and break condition to global repos update
Signed-off-by: frank-zsy <syzhao1988@126.com>
1 parent eccec62 commit 71e9dce

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/cron/tasks/updateGitlabRepoData/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ SELECT
4747
(dateDiff('hour', issue_updated_at, last_activity_at) >= 1) AS should_update_issue,
4848
(dateDiff('hour', mr_updated_at, last_activity_at) >= 1) AS should_update_mr
4949
FROM gitlab_repo_list WHERE should_update_issue OR should_update_mr
50+
ORDER BY RAND()
5051
LIMIT ${repoUpdateBatchSize};`);
5152
logger.info(`Got ${repos.length} repos to update`);
5253

src/cron/tasks/updateGitlabRepos.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const task: Task = {
2222
}
2323

2424
const tableName = 'gitlab_repo_list';
25+
const perPage = 100;
2526

2627
const createGitlabRepoListTable = async () => {
2728
const createTableQuery = `
@@ -156,7 +157,7 @@ const task: Task = {
156157
let totalCount = 0;
157158
do {
158159
try {
159-
projects = await getProjects(lastActivityAt, 100);
160+
projects = await getProjects(lastActivityAt, perPage);
160161
if (projects.length === 0) {
161162
logger.info(`No projects found starting from ${lastActivityAt}, task done.`);
162163
break;
@@ -169,7 +170,7 @@ const task: Task = {
169170
logger.error(`Error getting projects starting from ${lastActivityAt}: ${error.message}\n${error.stack}`);
170171
break;
171172
}
172-
} while (projects.length > 0 && totalCount < 20000);
173+
} while (projects.length === perPage && totalCount < 10000);
173174
logger.info(`Task done, total count: ${totalCount}`);
174175
}
175176
};

0 commit comments

Comments
 (0)