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!(
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
use conduit::{checked, debug_info};
|
||||
use conduit::{checked, debug_info, utils::math::usize_from_f64};
|
||||
use lru_cache::LruCache;
|
||||
use ruma::{
|
||||
api::{
|
||||
|
@ -161,11 +161,10 @@ impl From<CachedSpaceHierarchySummary> for SpaceHierarchyRoomsChunk {
|
|||
impl crate::Service for Service {
|
||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
let config = &args.server.config;
|
||||
let cache_size = f64::from(config.roomid_spacehierarchy_cache_capacity);
|
||||
let cache_size = cache_size * config.conduit_cache_capacity_modifier;
|
||||
Ok(Arc::new(Self {
|
||||
roomid_spacehierarchy_cache: Mutex::new(LruCache::new(
|
||||
(f64::from(config.roomid_spacehierarchy_cache_capacity) * config.conduit_cache_capacity_modifier)
|
||||
as usize,
|
||||
)),
|
||||
roomid_spacehierarchy_cache: Mutex::new(LruCache::new(usize_from_f64(cache_size)?)),
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -447,7 +446,7 @@ impl Service {
|
|||
}
|
||||
|
||||
pub async fn get_client_hierarchy(
|
||||
&self, sender_user: &UserId, room_id: &RoomId, limit: usize, short_room_ids: Vec<u64>, max_depth: usize,
|
||||
&self, sender_user: &UserId, room_id: &RoomId, limit: usize, short_room_ids: Vec<u64>, max_depth: u64,
|
||||
suggested_only: bool,
|
||||
) -> Result<client::space::get_hierarchy::v1::Response> {
|
||||
let mut parents = VecDeque::new();
|
||||
|
@ -514,7 +513,8 @@ impl Service {
|
|||
}
|
||||
}
|
||||
|
||||
if !children.is_empty() && parents.len() < max_depth {
|
||||
let parents_len: u64 = parents.len().try_into()?;
|
||||
if !children.is_empty() && parents_len < max_depth {
|
||||
parents.push_back(current_room.clone());
|
||||
stack.push(children);
|
||||
}
|
||||
|
@ -549,9 +549,8 @@ impl Service {
|
|||
Some(
|
||||
PaginationToken {
|
||||
short_room_ids,
|
||||
limit: UInt::new(max_depth as u64).expect("When sent in request it must have been valid UInt"),
|
||||
max_depth: UInt::new(max_depth as u64)
|
||||
.expect("When sent in request it must have been valid UInt"),
|
||||
limit: UInt::new(max_depth).expect("When sent in request it must have been valid UInt"),
|
||||
max_depth: UInt::new(max_depth).expect("When sent in request it must have been valid UInt"),
|
||||
suggested_only,
|
||||
}
|
||||
.to_string(),
|
||||
|
|
|
@ -6,7 +6,11 @@ use std::{
|
|||
sync::{Arc, Mutex as StdMutex, Mutex},
|
||||
};
|
||||
|
||||
use conduit::{error, utils::mutex_map, warn, Error, Result};
|
||||
use conduit::{
|
||||
error,
|
||||
utils::{math::usize_from_f64, mutex_map},
|
||||
warn, Error, Result,
|
||||
};
|
||||
use data::Data;
|
||||
use lru_cache::LruCache;
|
||||
use ruma::{
|
||||
|
@ -44,14 +48,15 @@ pub struct Service {
|
|||
impl crate::Service for Service {
|
||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
let config = &args.server.config;
|
||||
let server_visibility_cache_capacity =
|
||||
f64::from(config.server_visibility_cache_capacity) * config.conduit_cache_capacity_modifier;
|
||||
let user_visibility_cache_capacity =
|
||||
f64::from(config.user_visibility_cache_capacity) * config.conduit_cache_capacity_modifier;
|
||||
|
||||
Ok(Arc::new(Self {
|
||||
db: Data::new(args.db),
|
||||
server_visibility_cache: StdMutex::new(LruCache::new(
|
||||
(f64::from(config.server_visibility_cache_capacity) * config.conduit_cache_capacity_modifier) as usize,
|
||||
)),
|
||||
user_visibility_cache: StdMutex::new(LruCache::new(
|
||||
(f64::from(config.user_visibility_cache_capacity) * config.conduit_cache_capacity_modifier) as usize,
|
||||
)),
|
||||
server_visibility_cache: StdMutex::new(LruCache::new(usize_from_f64(server_visibility_cache_capacity)?)),
|
||||
user_visibility_cache: StdMutex::new(LruCache::new(usize_from_f64(user_visibility_cache_capacity)?)),
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::{
|
|||
sync::{Arc, Mutex as StdMutex, Mutex},
|
||||
};
|
||||
|
||||
use conduit::{checked, utils, Result};
|
||||
use conduit::{checked, utils, utils::math::usize_from_f64, Result};
|
||||
use data::Data;
|
||||
use lru_cache::LruCache;
|
||||
use ruma::{EventId, RoomId};
|
||||
|
@ -55,11 +55,10 @@ pub struct Service {
|
|||
impl crate::Service for Service {
|
||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
let config = &args.server.config;
|
||||
let cache_capacity = f64::from(config.stateinfo_cache_capacity) * config.conduit_cache_capacity_modifier;
|
||||
Ok(Arc::new(Self {
|
||||
db: Data::new(args.db),
|
||||
stateinfo_cache: StdMutex::new(LruCache::new(
|
||||
(f64::from(config.stateinfo_cache_capacity) * config.conduit_cache_capacity_modifier) as usize,
|
||||
)),
|
||||
stateinfo_cache: StdMutex::new(LruCache::new(usize_from_f64(cache_capacity)?)),
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue