fix needless pass by value

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-06-28 23:23:59 +00:00
parent 875d9e8b07
commit 57acc4f655
15 changed files with 40 additions and 42 deletions

View file

@ -17,7 +17,7 @@ impl Data {
}
/// Registers an appservice and returns the ID to the caller
pub(super) fn register_appservice(&self, yaml: Registration) -> Result<String> {
pub(super) fn register_appservice(&self, yaml: &Registration) -> Result<String> {
let id = yaml.id.as_str();
self.id_appserviceregistrations
.insert(id.as_bytes(), serde_yaml::to_string(&yaml).unwrap().as_bytes())?;

View file

@ -149,7 +149,7 @@ impl Service {
.await
.insert(yaml.id.clone(), yaml.clone().try_into()?);
self.db.register_appservice(yaml)
self.db.register_appservice(&yaml)
}
/// Remove an appservice registration

View file

@ -23,7 +23,7 @@ impl Data {
}
pub(super) fn create_file_metadata(
&self, sender_user: Option<&str>, mxc: String, width: u32, height: u32, content_disposition: Option<&str>,
&self, sender_user: Option<&str>, mxc: &str, width: u32, height: u32, content_disposition: Option<&str>,
content_type: Option<&str>,
) -> Result<Vec<u8>> {
let mut key = mxc.as_bytes().to_vec();
@ -56,7 +56,7 @@ impl Data {
Ok(key)
}
pub(super) fn delete_file_mxc(&self, mxc: String) -> Result<()> {
pub(super) fn delete_file_mxc(&self, mxc: &str) -> Result<()> {
debug!("MXC URI: {:?}", mxc);
let mut prefix = mxc.as_bytes().to_vec();
@ -82,7 +82,7 @@ impl Data {
}
/// Searches for all files with the given MXC
pub(super) fn search_mxc_metadata_prefix(&self, mxc: String) -> Result<Vec<Vec<u8>>> {
pub(super) fn search_mxc_metadata_prefix(&self, mxc: &str) -> Result<Vec<Vec<u8>>> {
debug!("MXC URI: {:?}", mxc);
let mut prefix = mxc.as_bytes().to_vec();
@ -106,7 +106,7 @@ impl Data {
}
pub(super) fn search_file_metadata(
&self, mxc: String, width: u32, height: u32,
&self, mxc: &str, width: u32, height: u32,
) -> Result<(Option<String>, Option<String>, Vec<u8>)> {
let mut prefix = mxc.as_bytes().to_vec();
prefix.push(0xFF);

View file

@ -59,7 +59,7 @@ impl Service {
/// Uploads a file.
pub async fn create(
&self, sender_user: Option<OwnedUserId>, mxc: String, content_disposition: Option<&str>,
&self, sender_user: Option<OwnedUserId>, mxc: &str, content_disposition: Option<&str>,
content_type: Option<&str>, file: &[u8],
) -> Result<()> {
// Width, Height = 0 if it's not a thumbnail
@ -79,13 +79,13 @@ impl Service {
}
/// Deletes a file in the database and from the media directory via an MXC
pub async fn delete(&self, mxc: String) -> Result<()> {
if let Ok(keys) = self.db.search_mxc_metadata_prefix(mxc.clone()) {
pub async fn delete(&self, mxc: &str) -> Result<()> {
if let Ok(keys) = self.db.search_mxc_metadata_prefix(mxc) {
for key in keys {
self.remove_media_file(&key).await?;
debug!("Deleting MXC {mxc} from database");
self.db.delete_file_mxc(mxc.clone())?;
self.db.delete_file_mxc(mxc)?;
}
Ok(())
@ -100,7 +100,7 @@ impl Service {
/// Uploads or replaces a file thumbnail.
#[allow(clippy::too_many_arguments)]
pub async fn upload_thumbnail(
&self, sender_user: Option<OwnedUserId>, mxc: String, content_disposition: Option<&str>,
&self, sender_user: Option<OwnedUserId>, mxc: &str, content_disposition: Option<&str>,
content_type: Option<&str>, width: u32, height: u32, file: &[u8],
) -> Result<()> {
let key = if let Some(user) = sender_user {
@ -119,7 +119,7 @@ impl Service {
}
/// Downloads a file.
pub async fn get(&self, mxc: String) -> Result<Option<FileMeta>> {
pub async fn get(&self, mxc: &str) -> Result<Option<FileMeta>> {
if let Ok((content_disposition, content_type, key)) = self.db.search_file_metadata(mxc, 0, 0) {
let mut file = Vec::new();
let path = self.get_media_file(&key);
@ -232,7 +232,7 @@ impl Service {
for mxc in remote_mxcs {
debug!("Deleting MXC {mxc} from database and filesystem");
self.delete(mxc).await?;
self.delete(&mxc).await?;
deletion_count = deletion_count.saturating_add(1);
}
@ -265,12 +265,12 @@ impl Service {
///
/// For width,height <= 96 the server uses another thumbnailing algorithm
/// which crops the image afterwards.
pub async fn get_thumbnail(&self, mxc: String, width: u32, height: u32) -> Result<Option<FileMeta>> {
pub async fn get_thumbnail(&self, mxc: &str, width: u32, height: u32) -> Result<Option<FileMeta>> {
let (width, height, crop) = self
.thumbnail_properties(width, height)
.unwrap_or((0, 0, false)); // 0, 0 because that's the original file
if let Ok((content_disposition, content_type, key)) = self.db.search_file_metadata(mxc.clone(), width, height) {
if let Ok((content_disposition, content_type, key)) = self.db.search_file_metadata(mxc, width, height) {
// Using saved thumbnail
let mut file = Vec::new();
let path = self.get_media_file(&key);
@ -281,7 +281,7 @@ impl Service {
content_type,
file: file.clone(),
}))
} else if let Ok((content_disposition, content_type, key)) = self.db.search_file_metadata(mxc.clone(), 0, 0) {
} else if let Ok((content_disposition, content_type, key)) = self.db.search_file_metadata(mxc, 0, 0) {
// Generate a thumbnail
let mut file = Vec::new();
let path = self.get_media_file(&key);

View file

@ -19,14 +19,14 @@ impl Data {
}
}
pub(super) fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()> {
match &pusher {
pub(super) fn set_pusher(&self, sender: &UserId, pusher: &set_pusher::v3::PusherAction) -> Result<()> {
match pusher {
set_pusher::v3::PusherAction::Post(data) => {
let mut key = sender.as_bytes().to_vec();
key.push(0xFF);
key.extend_from_slice(data.pusher.ids.pushkey.as_bytes());
self.senderkey_pusher
.insert(&key, &serde_json::to_vec(&pusher).expect("Pusher is valid JSON value"))?;
.insert(&key, &serde_json::to_vec(pusher).expect("Pusher is valid JSON value"))?;
Ok(())
},
set_pusher::v3::PusherAction::Delete(ids) => {

View file

@ -38,7 +38,7 @@ impl Service {
})
}
pub fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()> {
pub fn set_pusher(&self, sender: &UserId, pusher: &set_pusher::v3::PusherAction) -> Result<()> {
self.db.set_pusher(sender, pusher)
}

View file

@ -27,7 +27,7 @@ impl Data {
}
}
pub(super) fn readreceipt_update(&self, user_id: &UserId, room_id: &RoomId, event: ReceiptEvent) -> Result<()> {
pub(super) fn readreceipt_update(&self, user_id: &UserId, room_id: &RoomId, event: &ReceiptEvent) -> Result<()> {
let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xFF);
@ -56,7 +56,7 @@ impl Data {
self.readreceiptid_readreceipt.insert(
&room_latest_id,
&serde_json::to_vec(&event).expect("EduEvent::to_string always works"),
&serde_json::to_vec(event).expect("EduEvent::to_string always works"),
)?;
Ok(())

View file

@ -22,7 +22,7 @@ impl Service {
}
/// Replaces the previous read receipt.
pub fn readreceipt_update(&self, user_id: &UserId, room_id: &RoomId, event: ReceiptEvent) -> Result<()> {
pub fn readreceipt_update(&self, user_id: &UserId, room_id: &RoomId, event: &ReceiptEvent) -> Result<()> {
self.db.readreceipt_update(user_id, room_id, event)?;
services().sending.flush_room(room_id)?;

View file

@ -60,7 +60,7 @@ impl Data {
})
}
pub(super) fn save_statediff(&self, shortstatehash: u64, diff: StateDiff) -> Result<()> {
pub(super) fn save_statediff(&self, shortstatehash: u64, diff: &StateDiff) -> Result<()> {
let mut value = diff.parent.unwrap_or(0).to_be_bytes().to_vec();
for new in diff.added.iter() {
value.extend_from_slice(&new[..]);

View file

@ -200,7 +200,7 @@ impl Service {
// There is no parent layer, create a new state
self.db.save_statediff(
shortstatehash,
StateDiff {
&StateDiff {
parent: None,
added: statediffnew,
removed: statediffremoved,
@ -251,7 +251,7 @@ impl Service {
// Diff small enough, we add diff as layer on top of parent
self.db.save_statediff(
shortstatehash,
StateDiff {
&StateDiff {
parent: Some(parent.0),
added: statediffnew,
removed: statediffremoved,