Skip to content

Commit

Permalink
improve memory usage of map?
Browse files Browse the repository at this point in the history
  • Loading branch information
akarras committed Feb 4, 2024
1 parent eb12061 commit 2380304
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ultros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ image.workspace = true
isocountry = "0.3.2"
git-const.workspace = true
http-body-util = "0.1.0"
arrayvec = "0.7.4"
15 changes: 10 additions & 5 deletions ultros/src/analyzer_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use futures::StreamExt;
use itertools::Itertools;
use poise::serenity_prelude::Timestamp;
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use tracing::log::info;
use ultros_api_types::{websocket::ListingEventData, ActiveListing, Retainer};
use ultros_db::{
Expand Down Expand Up @@ -132,7 +131,7 @@ impl From<&ultros_api_types::SaleHistory> for SaleSummary {

#[derive(Debug, Default, Clone)]
pub(crate) struct SaleHistory {
pub(crate) item_map: HashMap<ItemKey, SmallVec<[SaleSummary; SALE_HISTORY_SIZE]>>,
pub(crate) item_map: HashMap<ItemKey, arrayvec::ArrayVec<SaleSummary, SALE_HISTORY_SIZE>>,
}

impl SaleHistory {
Expand All @@ -143,11 +142,17 @@ impl SaleHistory {
let entries = self
.item_map
.entry(sale.into())
.or_insert_with(SmallVec::new_const);
.or_default();
let sale: SaleSummary = sale.into();
if entries.len() == SALE_HISTORY_SIZE {
let _ = entries.pop();
let last_entry = entries.last().expect("We just checked len");
if last_entry.sale_date < sale.sale_date {
let _ = entries.pop();
entries.push(sale);
}
} else {
entries.push(sale);
}
entries.push(sale.into());
entries.sort_by_key(|sale| Reverse(sale.sale_date));
}
}
Expand Down
2 changes: 1 addition & 1 deletion ultros/src/web/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub async fn begin_login(
CookieBuilder::new("pkce_challenge", pkce_challenge.as_str().to_string())
.same_site(SameSite::Strict)
.secure(true)
.finish(),
.build(),
);
let cookies = cookies.add(Cookie::new("pkce_verifier", pkce_verifier.secret().clone()));

Expand Down

0 comments on commit 2380304

Please sign in to comment.