fix as conversions
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
7397064edd
commit
dcd7422c45
11 changed files with 107 additions and 51 deletions
|
@ -3,7 +3,7 @@ use std::{
|
|||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use conduit::{utils, Result, Server};
|
||||
use conduit::{utils, utils::math::usize_from_f64, Result, Server};
|
||||
use database::{Database, Map};
|
||||
use lru_cache::LruCache;
|
||||
|
||||
|
@ -16,7 +16,7 @@ impl Data {
|
|||
pub(super) fn new(server: &Arc<Server>, db: &Arc<Database>) -> Self {
|
||||
let config = &server.config;
|
||||
let cache_size = f64::from(config.auth_chain_cache_capacity);
|
||||
let cache_size = (cache_size * config.conduit_cache_capacity_modifier) as usize;
|
||||
let cache_size = usize_from_f64(cache_size * config.conduit_cache_capacity_modifier).expect("valid cache size");
|
||||
Self {
|
||||
shorteventid_authchain: db["shorteventid_authchain"].clone(),
|
||||
auth_chain_cache: Mutex::new(LruCache::new(cache_size)),
|
||||
|
|
|
@ -43,11 +43,11 @@ impl Service {
|
|||
|
||||
#[tracing::instrument(skip_all, name = "auth_chain")]
|
||||
pub async fn get_auth_chain(&self, room_id: &RoomId, starting_events: &[&EventId]) -> Result<Vec<u64>> {
|
||||
const NUM_BUCKETS: u64 = 50; //TODO: change possible w/o disrupting db?
|
||||
const NUM_BUCKETS: usize = 50; //TODO: change possible w/o disrupting db?
|
||||
const BUCKET: BTreeSet<(u64, &EventId)> = BTreeSet::new();
|
||||
|
||||
let started = std::time::Instant::now();
|
||||
let mut buckets = [BUCKET; NUM_BUCKETS as usize];
|
||||
let mut buckets = [BUCKET; NUM_BUCKETS];
|
||||
for (i, &short) in services()
|
||||
.rooms
|
||||
.short
|
||||
|
@ -55,8 +55,9 @@ impl Service {
|
|||
.iter()
|
||||
.enumerate()
|
||||
{
|
||||
let bucket = validated!(short % NUM_BUCKETS)?;
|
||||
buckets[bucket as usize].insert((short, starting_events[i]));
|
||||
let bucket: usize = short.try_into()?;
|
||||
let bucket: usize = validated!(bucket % NUM_BUCKETS)?;
|
||||
buckets[bucket].insert((short, starting_events[i]));
|
||||
}
|
||||
|
||||
debug!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue