1
1
use futures:: stream:: { iter, try_unfold} ;
2
2
use futures:: { Stream , TryStreamExt } ;
3
- use itertools:: Itertools ;
4
3
use mongodb:: bson:: { doc, Document } ;
5
4
use mongodb:: options:: * ;
6
5
use mongodb:: { bson, Database , IndexModel } ;
@@ -35,9 +34,6 @@ pub struct Account {
35
34
#[ serde( rename = "lbts" ) ]
36
35
#[ serde_as( as = "Option<bson::DateTime>" ) ]
37
36
pub last_battle_time : Option < DateTime > ,
38
-
39
- #[ serde( default ) ]
40
- pub prio : bool ,
41
37
}
42
38
43
39
impl TypedDocument for Account {
@@ -46,7 +42,7 @@ impl TypedDocument for Account {
46
42
47
43
#[ async_trait]
48
44
impl Indexes for Account {
49
- type I = [ IndexModel ; 3 ] ;
45
+ type I = [ IndexModel ; 2 ] ;
50
46
51
47
fn indexes ( ) -> Self :: I {
52
48
[
@@ -57,14 +53,6 @@ impl Indexes for Account {
57
53
. keys ( doc ! { "rlm" : 1 , "aid" : 1 } )
58
54
. options ( IndexOptions :: builder ( ) . unique ( true ) . build ( ) )
59
55
. build ( ) ,
60
- IndexModel :: builder ( )
61
- . keys ( doc ! { "rlm" : 1 , "prio" : 1 } )
62
- . options (
63
- IndexOptions :: builder ( )
64
- . partial_filter_expression ( doc ! { "prio" : { "$eq" : true } } )
65
- . build ( ) ,
66
- )
67
- . build ( ) ,
68
56
]
69
57
}
70
58
}
@@ -75,7 +63,6 @@ impl Account {
75
63
id : account_id,
76
64
realm,
77
65
last_battle_time : None ,
78
- prio : false ,
79
66
}
80
67
}
81
68
}
@@ -129,10 +116,7 @@ impl Account {
129
116
account_id : wargaming:: AccountId ,
130
117
) -> Result {
131
118
let filter = doc ! { "rlm" : realm. to_str( ) , "aid" : account_id } ;
132
- let update = doc ! {
133
- "$setOnInsert" : { "lbts" : null, "pts" : [ ] } ,
134
- // TODO: "$set": { "prio": true },
135
- } ;
119
+ let update = doc ! { "$setOnInsert" : { "lbts" : null } } ;
136
120
let options = UpdateOptions :: builder ( ) . upsert ( true ) . build ( ) ;
137
121
Self :: collection ( in_)
138
122
. update_one ( filter, update, options)
@@ -151,28 +135,17 @@ impl Account {
151
135
debug ! ( sample_size, "retrieving…" ) ;
152
136
let start_instant = Instant :: now ( ) ;
153
137
154
- // Retrieve marked accounts:
138
+ // Retrieve new accounts:
155
139
let mut accounts = {
156
- debug ! ( "querying marked high-prio accounts…" ) ;
157
- let filter = doc ! { "rlm" : realm. to_str( ) , "prio " : true } ;
140
+ debug ! ( "querying new accounts…" ) ;
141
+ let filter = doc ! { "rlm" : realm. to_str( ) , "lbts " : null } ;
158
142
let options = FindOptions :: builder ( ) . limit ( sample_size as i64 ) . build ( ) ;
159
- let prio_accounts = Self :: find_vec ( from, filter, options) . await ?;
143
+ let new_accounts = Self :: find_vec ( from, filter, options) . await ?;
160
144
debug ! (
161
- n_prio_accounts = prio_accounts . len( ) ,
145
+ n_new_accounts = new_accounts . len( ) ,
162
146
elapsed = ?start_instant. elapsed( ) ,
163
147
) ;
164
- if !prio_accounts. is_empty ( ) {
165
- debug ! ( n_prio_accounts = prio_accounts. len( ) , "clearing the prio flags…" ) ;
166
- let query = doc ! {
167
- "rlm" : realm. to_str( ) ,
168
- "aid" : { "$in" : prio_accounts. iter( ) . map( |account| account. id) . collect_vec( ) } ,
169
- } ;
170
- Self :: collection ( from)
171
- . update_many ( query, doc ! { "$set" : { "prio" : false } } , None )
172
- . await ?;
173
- debug ! ( elapsed = ?start_instant. elapsed( ) , "cleared the prio flags" ) ;
174
- }
175
- prio_accounts
148
+ new_accounts
176
149
} ;
177
150
178
151
// Retrieve random selection of accounts:
0 commit comments