Skip to content
This repository was archived by the owner on Mar 18, 2023. It is now read-only.

Commit 39a0a88

Browse files
committed
⚡️ Database: drop the prio flag
1 parent 97614ad commit 39a0a88

File tree

2 files changed

+8
-36
lines changed

2 files changed

+8
-36
lines changed

src/crawler.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ impl Crawler {
208208
id: account.id,
209209
realm: self.realm,
210210
last_battle_time: Some(account_info.last_battle_time),
211-
prio: false,
212211
};
213212
let account_snapshot =
214213
database::AccountSnapshot::new(self.realm, &account_info, tank_last_battle_times);

src/database/mongodb/models/account.rs

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use futures::stream::{iter, try_unfold};
22
use futures::{Stream, TryStreamExt};
3-
use itertools::Itertools;
43
use mongodb::bson::{doc, Document};
54
use mongodb::options::*;
65
use mongodb::{bson, Database, IndexModel};
@@ -35,9 +34,6 @@ pub struct Account {
3534
#[serde(rename = "lbts")]
3635
#[serde_as(as = "Option<bson::DateTime>")]
3736
pub last_battle_time: Option<DateTime>,
38-
39-
#[serde(default)]
40-
pub prio: bool,
4137
}
4238

4339
impl TypedDocument for Account {
@@ -46,7 +42,7 @@ impl TypedDocument for Account {
4642

4743
#[async_trait]
4844
impl Indexes for Account {
49-
type I = [IndexModel; 3];
45+
type I = [IndexModel; 2];
5046

5147
fn indexes() -> Self::I {
5248
[
@@ -57,14 +53,6 @@ impl Indexes for Account {
5753
.keys(doc! { "rlm": 1, "aid": 1 })
5854
.options(IndexOptions::builder().unique(true).build())
5955
.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(),
6856
]
6957
}
7058
}
@@ -75,7 +63,6 @@ impl Account {
7563
id: account_id,
7664
realm,
7765
last_battle_time: None,
78-
prio: false,
7966
}
8067
}
8168
}
@@ -129,10 +116,7 @@ impl Account {
129116
account_id: wargaming::AccountId,
130117
) -> Result {
131118
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 } };
136120
let options = UpdateOptions::builder().upsert(true).build();
137121
Self::collection(in_)
138122
.update_one(filter, update, options)
@@ -151,28 +135,17 @@ impl Account {
151135
debug!(sample_size, "retrieving…");
152136
let start_instant = Instant::now();
153137

154-
// Retrieve marked accounts:
138+
// Retrieve new accounts:
155139
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 };
158142
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?;
160144
debug!(
161-
n_prio_accounts = prio_accounts.len(),
145+
n_new_accounts = new_accounts.len(),
162146
elapsed = ?start_instant.elapsed(),
163147
);
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
176149
};
177150

178151
// Retrieve random selection of accounts:

0 commit comments

Comments
 (0)