-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync_scores.ts
43 lines (33 loc) · 1.06 KB
/
sync_scores.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { args, BaseCommand } from '@adonisjs/core/ace'
import type { CommandOptions } from '@adonisjs/core/types/ace'
import { User } from '#models/user'
import { scoreForUser } from '#services/score/calculate'
export default class SyncScores extends BaseCommand {
static commandName = 'sync:scores'
static description = 'Sync scores for users'
static options: CommandOptions = {
startApp: true,
}
@args.string()
declare farcasterId: string
async run() {
this.logger.info('Starting score calculation')
let processedUsers = 0
let users
if (this.farcasterId !== '-1') {
users = await User.query().where('fid', this.farcasterId)
} else {
users = await User.query().orderBy('id', 'desc')
}
this.logger.info(`Total users: ${users.length}`)
for (let user of users) {
processedUsers += 1
const score = await scoreForUser(user)
user.score = score
await user.save()
this.logger.info(
`Processing scores for #${processedUsers} ${user.username} -> Score: ${score}`
)
}
}
}