File tree Expand file tree Collapse file tree 1 file changed +23
-6
lines changed Expand file tree Collapse file tree 1 file changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -101,11 +101,24 @@ const importUptime = async () => {
101
101
}
102
102
103
103
// 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
+ )
109
122
110
123
// group by account
111
124
const grouped = groupBy ( uptime , 'account' )
@@ -149,9 +162,13 @@ const importUptime = async () => {
149
162
}
150
163
151
164
// 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' )
153
166
. whereNotIn ( 'account' , Object . keys ( grouped ) )
154
167
. delete ( )
168
+
169
+ logger (
170
+ `removed ${ res } outdated rollup rows for representatives without uptime in the last 14 days`
171
+ )
155
172
}
156
173
157
174
if ( isMain ( import . meta. url ) ) {
You can’t perform that action at this time.
0 commit comments