From 76bee6f3a4cbb5f4f358d7e2509f2a5c83d0d89e Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Fri, 11 Feb 2022 23:45:49 +0800 Subject: [PATCH] fix(status): guild chart always empty --- packages/core/src/orm.ts | 4 ++-- plugins/frontend/status/client/charts/utils.ts | 4 +++- plugins/frontend/status/src/stats.ts | 15 ++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/core/src/orm.ts b/packages/core/src/orm.ts index 275dcf5406..af6d68420b 100644 --- a/packages/core/src/orm.ts +++ b/packages/core/src/orm.ts @@ -324,8 +324,8 @@ export namespace Eval { } export interface BooleanExpr extends UniveralExpr { - $eq?: [Number, Number] - $ne?: [Number, Number] + $eq?: [Number, Number] | [String, String] | [Boolean, Boolean] + $ne?: [Number, Number] | [String, String] | [Boolean, Boolean] $gt?: [Number, Number] $gte?: [Number, Number] $lt?: [Number, Number] diff --git a/plugins/frontend/status/client/charts/utils.ts b/plugins/frontend/status/client/charts/utils.ts index e92bffecf0..0e57d2cb77 100644 --- a/plugins/frontend/status/client/charts/utils.ts +++ b/plugins/frontend/status/client/charts/utils.ts @@ -15,7 +15,9 @@ export function createChart({ title, fields, options }: ChartOptions) { return Card.create(() => { const option = options(store) if (!option) return - return h(resolveComponent('k-card'), { class: 'frameless', title }, h(VChart, { option, autoresize: true })) + return h(resolveComponent('k-card'), { class: 'frameless', title }, () => { + return h(VChart, { option, autoresize: true }) + }) }, fields) } diff --git a/plugins/frontend/status/src/stats.ts b/plugins/frontend/status/src/stats.ts index cd26033659..505bf75d28 100644 --- a/plugins/frontend/status/src/stats.ts +++ b/plugins/frontend/status/src/stats.ts @@ -238,11 +238,11 @@ class StatisticsProvider extends DataService { private extendGuilds: StatisticsProvider.Extension = async (payload, data) => { const groupSet = new Set() payload.guilds = [] - const groupMap = Object.fromEntries(data.guilds.map(g => [g.id, g])) + const groupMap = Object.fromEntries(data.guilds.map(g => [`${g.platform}:${g.id}`, g])) const messageMap = average(data.daily.map(data => data.group)) const updateList: Pick[] = [] - async function getGroupInfo(bot: Bot) { + async function getGuildInfo(bot: Bot) { const { platform } = bot const guilds = await bot.getGuildList() for (const { guildId, guildName: name } of guilds) { @@ -261,7 +261,10 @@ class StatisticsProvider extends DataService { } } - await Promise.all(this.ctx.bots.map(bot => getGroupInfo(bot).catch(noop))) + await Promise.all(this.ctx.bots.map(async (bot) => { + if (bot.status !== 'online') return + await getGuildInfo(bot).catch(logger.warn) + })) for (const key in messageMap) { if (!groupSet.has(key) && groupMap[key]) { @@ -286,7 +289,9 @@ class StatisticsProvider extends DataService { this.ctx.database.get('stats_daily', { time }, { sort, limit: RECENT_LENGTH }), this.ctx.database.get('stats_hourly', { time }, { sort, limit: 24 * RECENT_LENGTH }), this.ctx.database.get('stats_longterm', { time }, { sort }), - this.ctx.database.get('channel', {}, ['platform', 'id', 'name', 'assignee']), + this.ctx.database.get('channel', { + $expr: { $eq: [{ $: 'id' }, { $: 'guildId' }] }, + }, ['platform', 'id', 'name', 'assignee']), ]) const data = { daily, hourly, longterm, guilds } const payload = {} as StatisticsProvider.Payload @@ -323,7 +328,7 @@ namespace StatisticsProvider { export interface Data { extension?: StatisticsProvider.Payload - guilds: Pick[] + guilds: Pick[] daily: Record>[] hourly: ({ time: Date } & Record)[] longterm: ({ time: Date } & Record)[]