mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2024-11-27 20:45:30 +00:00
use saturating_add and vec with_capacity in even more places
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
4ea7af5780
commit
83220b43a2
|
@ -23,7 +23,7 @@ pub(crate) async fn delete(
|
|||
debug!("Got event ID to delete media from: {event_id}");
|
||||
|
||||
let mut mxc_urls = vec![];
|
||||
let mut mxc_deletion_count = 0;
|
||||
let mut mxc_deletion_count: usize = 0;
|
||||
|
||||
// parsing the PDU for any MXC URLs begins here
|
||||
if let Some(event_json) = services().rooms.timeline.get_pdu_json(&event_id)? {
|
||||
|
@ -123,7 +123,7 @@ pub(crate) async fn delete(
|
|||
|
||||
for mxc_url in mxc_urls {
|
||||
services().media.delete(mxc_url).await?;
|
||||
mxc_deletion_count += 1;
|
||||
mxc_deletion_count = mxc_deletion_count.saturating_add(1);
|
||||
}
|
||||
|
||||
return Ok(RoomMessageEventContent::text_plain(format!(
|
||||
|
|
|
@ -185,7 +185,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
|
|||
.try_into()
|
||||
.expect("#admins:server_name is a valid alias name");
|
||||
|
||||
let mut room_ban_count = 0;
|
||||
let mut room_ban_count: usize = 0;
|
||||
let mut room_ids: Vec<OwnedRoomId> = Vec::new();
|
||||
|
||||
for &room in &rooms_s {
|
||||
|
@ -297,7 +297,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
|
|||
for room_id in room_ids {
|
||||
if services().rooms.metadata.ban_room(&room_id, true).is_ok() {
|
||||
debug!("Banned {room_id} successfully");
|
||||
room_ban_count += 1;
|
||||
room_ban_count = room_ban_count.saturating_add(1);
|
||||
}
|
||||
|
||||
debug!("Making all users leave the room {}", &room_id);
|
||||
|
|
|
@ -64,8 +64,8 @@ impl TryFrom<Vec<Namespace>> for NamespaceRegex {
|
|||
type Error = regex::Error;
|
||||
|
||||
fn try_from(value: Vec<Namespace>) -> Result<Self, regex::Error> {
|
||||
let mut exclusive = vec![];
|
||||
let mut non_exclusive = vec![];
|
||||
let mut exclusive = Vec::with_capacity(value.len());
|
||||
let mut non_exclusive = Vec::with_capacity(value.len());
|
||||
|
||||
for namespace in value {
|
||||
if namespace.exclusive {
|
||||
|
|
|
@ -305,7 +305,7 @@ impl Service {
|
|||
pub fn block_non_admin_invites(&self) -> bool { self.config.block_non_admin_invites }
|
||||
|
||||
pub fn supported_room_versions(&self) -> Vec<RoomVersionId> {
|
||||
let mut room_versions: Vec<RoomVersionId> = vec![];
|
||||
let mut room_versions: Vec<RoomVersionId> = Vec::with_capacity(self.stable_room_versions.len());
|
||||
room_versions.extend(self.stable_room_versions.clone());
|
||||
if self.allow_unstable_room_versions() {
|
||||
room_versions.extend(self.unstable_room_versions.clone());
|
||||
|
|
|
@ -182,7 +182,7 @@ impl Service {
|
|||
|
||||
/// Deletes all remote only media files in the given at or after
|
||||
/// time/duration. Returns a u32 with the amount of media files deleted.
|
||||
pub async fn delete_all_remote_media_at_after_time(&self, time: String) -> Result<u32> {
|
||||
pub async fn delete_all_remote_media_at_after_time(&self, time: String) -> Result<usize> {
|
||||
let all_keys = self.db.get_all_media_keys();
|
||||
|
||||
let user_duration: SystemTime = match cyborgtime::parse_duration(&time) {
|
||||
|
@ -278,12 +278,12 @@ impl Service {
|
|||
|
||||
debug!("Deleting media now in the past \"{:?}\".", user_duration);
|
||||
|
||||
let mut deletion_count = 0;
|
||||
let mut deletion_count: usize = 0;
|
||||
|
||||
for mxc in remote_mxcs {
|
||||
debug!("Deleting MXC {mxc} from database and filesystem");
|
||||
self.delete(mxc).await?;
|
||||
deletion_count += 1;
|
||||
deletion_count = deletion_count.saturating_add(1);
|
||||
}
|
||||
|
||||
Ok(deletion_count)
|
||||
|
|
|
@ -54,9 +54,9 @@ impl Service {
|
|||
"start",
|
||||
);
|
||||
|
||||
let mut hits = 0;
|
||||
let mut misses = 0;
|
||||
let mut full_auth_chain = Vec::new();
|
||||
let mut hits: usize = 0;
|
||||
let mut misses: usize = 0;
|
||||
let mut full_auth_chain = Vec::with_capacity(buckets.len());
|
||||
for chunk in buckets {
|
||||
if chunk.is_empty() {
|
||||
continue;
|
||||
|
@ -70,13 +70,13 @@ impl Service {
|
|||
{
|
||||
trace!("Found cache entry for whole chunk");
|
||||
full_auth_chain.extend(cached.iter().copied());
|
||||
hits += 1;
|
||||
hits = hits.saturating_add(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut hits2 = 0;
|
||||
let mut misses2 = 0;
|
||||
let mut chunk_cache = Vec::new();
|
||||
let mut hits2: usize = 0;
|
||||
let mut misses2: usize = 0;
|
||||
let mut chunk_cache = Vec::with_capacity(chunk.len());
|
||||
for (sevent_id, event_id) in chunk {
|
||||
if let Some(cached) = services()
|
||||
.rooms
|
||||
|
@ -85,7 +85,7 @@ impl Service {
|
|||
{
|
||||
trace!(?event_id, "Found cache entry for event");
|
||||
chunk_cache.extend(cached.iter().copied());
|
||||
hits2 += 1;
|
||||
hits2 = hits2.saturating_add(1);
|
||||
} else {
|
||||
let auth_chain = self.get_auth_chain_inner(room_id, event_id)?;
|
||||
services()
|
||||
|
@ -93,7 +93,7 @@ impl Service {
|
|||
.auth_chain
|
||||
.cache_auth_chain(vec![sevent_id], &auth_chain)?;
|
||||
chunk_cache.extend(auth_chain.iter());
|
||||
misses2 += 1;
|
||||
misses2 = misses2.saturating_add(1);
|
||||
debug!(
|
||||
event_id = ?event_id,
|
||||
chain_length = ?auth_chain.len(),
|
||||
|
@ -111,7 +111,7 @@ impl Service {
|
|||
.auth_chain
|
||||
.cache_auth_chain_vec(chunk_key, &chunk_cache)?;
|
||||
full_auth_chain.extend(chunk_cache.iter());
|
||||
misses += 1;
|
||||
misses = misses.saturating_add(1);
|
||||
debug!(
|
||||
chunk_cache_length = ?chunk_cache.len(),
|
||||
hits = ?hits2,
|
||||
|
|
Loading…
Reference in a new issue