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

Commit

Permalink
⚡️ Database: drop the prio flag
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Oct 4, 2022
1 parent 97614ad commit 39a0a88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ impl Crawler {
id: account.id,
realm: self.realm,
last_battle_time: Some(account_info.last_battle_time),
prio: false,
};
let account_snapshot =
database::AccountSnapshot::new(self.realm, &account_info, tank_last_battle_times);
Expand Down
43 changes: 8 additions & 35 deletions src/database/mongodb/models/account.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use futures::stream::{iter, try_unfold};
use futures::{Stream, TryStreamExt};
use itertools::Itertools;
use mongodb::bson::{doc, Document};
use mongodb::options::*;
use mongodb::{bson, Database, IndexModel};
Expand Down Expand Up @@ -35,9 +34,6 @@ pub struct Account {
#[serde(rename = "lbts")]
#[serde_as(as = "Option<bson::DateTime>")]
pub last_battle_time: Option<DateTime>,

#[serde(default)]
pub prio: bool,
}

impl TypedDocument for Account {
Expand All @@ -46,7 +42,7 @@ impl TypedDocument for Account {

#[async_trait]
impl Indexes for Account {
type I = [IndexModel; 3];
type I = [IndexModel; 2];

fn indexes() -> Self::I {
[
Expand All @@ -57,14 +53,6 @@ impl Indexes for Account {
.keys(doc! { "rlm": 1, "aid": 1 })
.options(IndexOptions::builder().unique(true).build())
.build(),
IndexModel::builder()
.keys(doc! { "rlm": 1, "prio": 1 })
.options(
IndexOptions::builder()
.partial_filter_expression(doc! { "prio": {"$eq": true} })
.build(),
)
.build(),
]
}
}
Expand All @@ -75,7 +63,6 @@ impl Account {
id: account_id,
realm,
last_battle_time: None,
prio: false,
}
}
}
Expand Down Expand Up @@ -129,10 +116,7 @@ impl Account {
account_id: wargaming::AccountId,
) -> Result {
let filter = doc! { "rlm": realm.to_str(), "aid": account_id };
let update = doc! {
"$setOnInsert": { "lbts": null, "pts": [] },
// TODO: "$set": { "prio": true },
};
let update = doc! { "$setOnInsert": { "lbts": null } };
let options = UpdateOptions::builder().upsert(true).build();
Self::collection(in_)
.update_one(filter, update, options)
Expand All @@ -151,28 +135,17 @@ impl Account {
debug!(sample_size, "retrieving…");
let start_instant = Instant::now();

// Retrieve marked accounts:
// Retrieve new accounts:
let mut accounts = {
debug!("querying marked high-prio accounts…");
let filter = doc! { "rlm": realm.to_str(), "prio": true };
debug!("querying new accounts…");
let filter = doc! { "rlm": realm.to_str(), "lbts": null };
let options = FindOptions::builder().limit(sample_size as i64).build();
let prio_accounts = Self::find_vec(from, filter, options).await?;
let new_accounts = Self::find_vec(from, filter, options).await?;
debug!(
n_prio_accounts = prio_accounts.len(),
n_new_accounts = new_accounts.len(),
elapsed = ?start_instant.elapsed(),
);
if !prio_accounts.is_empty() {
debug!(n_prio_accounts = prio_accounts.len(), "clearing the prio flags…");
let query = doc! {
"rlm": realm.to_str(),
"aid": { "$in": prio_accounts.iter().map(|account| account.id).collect_vec() },
};
Self::collection(from)
.update_many(query, doc! { "$set": { "prio": false } }, None)
.await?;
debug!(elapsed = ?start_instant.elapsed(), "cleared the prio flags");
}
prio_accounts
new_accounts
};

// Retrieve random selection of accounts:
Expand Down

0 comments on commit 39a0a88

Please sign in to comment.