Skip to content

Commit 0829e1d

Browse files
committed
fix: limit uptime rollups to representatives above minimum tracking weight
1 parent 1c047be commit 0829e1d

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

scripts/import-uptime.mjs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,24 @@ const importUptime = async () => {
101101
}
102102

103103
// calculate rollup
104-
const uptime = await db('representatives_uptime').where(
105-
'timestamp',
106-
'>',
107-
dayjs().subtract('14', 'days').unix()
108-
)
104+
const uptime = await db('representatives_uptime')
105+
.select('representatives_uptime.*')
106+
.leftJoin(
107+
'accounts_meta_index',
108+
'representatives_uptime.account',
109+
'=',
110+
'accounts_meta_index.account'
111+
)
112+
.where(
113+
'representatives_uptime.timestamp',
114+
'>',
115+
dayjs().subtract('14', 'days').unix()
116+
)
117+
.where(
118+
'accounts_meta_index.weight',
119+
'>=',
120+
REPRESENTATIVE_TRACKING_MINIMUM_VOTING_WEIGHT
121+
)
109122

110123
// group by account
111124
const grouped = groupBy(uptime, 'account')
@@ -149,9 +162,13 @@ const importUptime = async () => {
149162
}
150163

151164
// remove rows for representatives without uptime in the last 14 days
152-
await db('representatives_uptime_rollup_2hour')
165+
const res = await db('representatives_uptime_rollup_2hour')
153166
.whereNotIn('account', Object.keys(grouped))
154167
.delete()
168+
169+
logger(
170+
`removed ${res} outdated rollup rows for representatives without uptime in the last 14 days`
171+
)
155172
}
156173

157174
if (isMain(import.meta.url)) {

0 commit comments

Comments
 (0)