From 909be3caa5ad19b439c0695293d818b46277e4b3 Mon Sep 17 00:00:00 2001 From: Frank Zhao Date: Mon, 15 Jan 2024 16:46:38 +0800 Subject: [PATCH] fix: fix community openrank org_id and org_login (#1503) Signed-off-by: frank-zsy --- src/cron/tasks/community_openrank.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cron/tasks/community_openrank.ts b/src/cron/tasks/community_openrank.ts index cadf241d2..1e4f063d2 100644 --- a/src/cron/tasks/community_openrank.ts +++ b/src/cron/tasks/community_openrank.ts @@ -46,9 +46,13 @@ const task: Task = { const createTable = async () => { const q = `CREATE TABLE IF NOT EXISTS ${openrankTable} ( - \`repo_id\` UInt64, \`platform\` Enum8('GitHub' = 1, 'Gitee' = 2, 'AtomGit' = 3, 'GitLab.com' = 4, 'Gitea' = 5, 'GitLab.cn' = 6), + \`repo_id\` UInt64, + \`repo_name\` LowCardinality(String), + \`org_id\` UInt64, + \`org_login\` LowCardinality(String), \`actor_id\` UInt64, + \`actor_login\` LowCardinality(String), \`issue_number\` UInt32, \`created_at\` DateTime, \`openrank\` Float @@ -139,13 +143,13 @@ const task: Task = { repoOrgMap.clear(); actorNameMap.clear(); const yyyymm = `${y}${m.toString().padStart(2, '0')}`; - const repoResult = await queryClickhouse(`SELECT DISTINCT platform, repo_id, argMax(repo_name, created_at) FROM events WHERE toYYYYMM(created_at) = ${yyyymm} AND repo_id IN (SELECT id FROM export_repo) GROUP BY repo_id, platform`, { format: 'JSONCompactEachRow' }); + const repoResult = await queryClickhouse(`SELECT platform, repo_id, argMax(repo_name, created_at), argMax(org_id, created_at), argMax(org_login, created_at) FROM events WHERE toYYYYMM(created_at) = ${yyyymm} AND repo_id IN (SELECT id FROM export_repo) GROUP BY repo_id, platform`, { format: 'JSONCompactEachRow' }); repoResult.forEach(row => { const [platform, repoId, repoName, orgId, orgLogin] = row; repoNameMap.set(`${platform}_${repoId}`, repoName); repoOrgMap.set(`${platform}_${repoId}`, { id: orgId, login: orgLogin }); }); - const actorResult = await queryClickhouse(`SELECT DISTINCT platform, actor_id, argMax(actor_login, created_at) FROM events WHERE toYYYYMM(created_at) = ${yyyymm} AND repo_id IN (SELECT id FROM export_repo) GROUP BY actor_id, platform`, { format: 'JSONCompactEachRow' }); + const actorResult = await queryClickhouse(`SELECT platform, actor_id, argMax(actor_login, created_at) FROM events WHERE toYYYYMM(created_at) = ${yyyymm} AND repo_id IN (SELECT id FROM export_repo) GROUP BY actor_id, platform`, { format: 'JSONCompactEachRow' }); actorResult.forEach(row => { const [platform, actorId, actorLogin] = row; actorNameMap.set(`${platform}_${actorId}`, actorLogin);