Skip to content

Commit

Permalink
fix(webui): fix database incompatibility, fix #295
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jul 5, 2021
1 parent 3c2df53 commit cc27cd8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-webui/src/database/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class MongoSynchronizer implements Synchronizer {
logger.debug('stats updated')
}

async download(date: Date) {
const time = { $lt: new Date(date) }
async download() {
const time = { $lt: new Date() }
const coll = this.db.collection('plugin-status')
const hourly = await coll.find({ type: 'hourly', time }).sort({ time: -1 }).limit(24 * RECENT_LENGTH).toArray()
const daily = await coll.find({ type: 'daily', time }).sort({ time: -1 }).limit(RECENT_LENGTH).toArray()
Expand Down
11 changes: 5 additions & 6 deletions packages/plugin-webui/src/database/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,13 @@ class MysqlSynchronizer implements Synchronizer {
await this.db.query(sqls)
}

async download(date: Date) {
const dateString = date.toLocaleDateString()
async download() {
const [daily, hourly, longterm, groups] = await this.db.query([
'SELECT * FROM `stats_daily` WHERE `time` < DATE(?) ORDER BY `time` DESC LIMIT ?',
'SELECT * FROM `stats_hourly` WHERE `time` < DATE(?) ORDER BY `time` DESC LIMIT ?',
'SELECT * FROM `stats_longterm` WHERE `time` < DATE(?) ORDER BY `time` DESC',
'SELECT * FROM `stats_daily` WHERE `time` < CURRENT_TIMESTAMP ORDER BY `time` DESC LIMIT ?',
'SELECT * FROM `stats_hourly` WHERE `time` < CURRENT_TIMESTAMP ORDER BY `time` DESC LIMIT ?',
'SELECT * FROM `stats_longterm` WHERE `time` < CURRENT_TIMESTAMP ORDER BY `time` DESC',
'SELECT `id`, `name`, `assignee` FROM `channel`',
], [dateString, RECENT_LENGTH, dateString, 24 * RECENT_LENGTH, dateString])
], [RECENT_LENGTH, 24 * RECENT_LENGTH])
return { daily, hourly, longterm, groups }
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-webui/src/payload/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Synchronizer {
longterm: Record<Synchronizer.LongtermField, number>
addDaily(field: Synchronizer.DailyField, key: string | number): void
upload(date: Date): Promise<void>
download(date: Date): Promise<Synchronizer.Data>
download(): Promise<Synchronizer.Data>
}

export namespace Synchronizer {
Expand Down Expand Up @@ -209,8 +209,8 @@ class Statistics {
await this.ctx.database.update('channel', updateList)
}

async download(date: Date) {
const data = await this.sync.download(date)
async download() {
const data = await this.sync.download()
const payload = {} as Statistics.Payload
await Promise.all(this.callbacks.map(cb => cb(payload, data)))
return payload
Expand All @@ -221,7 +221,7 @@ class Statistics {
const date = new Date()
const dateNumber = Time.getDateNumber(date, date.getTimezoneOffset())
if (dateNumber !== this.cachedDate) {
this.cachedData = this.download(date)
this.cachedData = this.download()
this.cachedDate = dateNumber
}
return this.cachedData
Expand Down

0 comments on commit cc27cd8

Please sign in to comment.