fix clippy performance and sus warnings, remove 1 unwrap, forgot to increment db version

Signed-off-by: strawberry <strawberry@pupbrain.dev>
This commit is contained in:
strawberry 2023-11-25 23:20:13 -05:00 committed by strawberry
parent b4e2f7ca37
commit 2dc1c1fdcb
7 changed files with 47 additions and 22 deletions

View file

@ -21,7 +21,10 @@ where
SendAccessToken::IfRequired(hs_token),
&[MatrixVersion::V1_0],
)
.unwrap()
.map_err(|e| {
warn!("Failed to find destination {}: {}", destination, e);
Error::BadServerResponse("Invalid destination")
})?
.map(|body| body.freeze());
let mut parts = http_request.uri().clone().into_parts();

View file

@ -84,12 +84,11 @@ pub async fn set_displayname_route(
);
let state_lock = mutex_state.lock().await;
let _ = services().rooms.timeline.build_and_append_pdu(
pdu_builder,
sender_user,
&room_id,
&state_lock,
);
let _ = services()
.rooms
.timeline
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock)
.await;
}
if services().globals.allow_local_presence() {
@ -207,12 +206,11 @@ pub async fn set_avatar_url_route(
);
let state_lock = mutex_state.lock().await;
let _ = services().rooms.timeline.build_and_append_pdu(
pdu_builder,
sender_user,
&room_id,
&state_lock,
);
let _ = services()
.rooms
.timeline
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock)
.await;
}
if services().globals.allow_local_presence() {

View file

@ -427,7 +427,14 @@ impl KeyValueDatabase {
}
// If the database has any data, perform data migrations before starting
let latest_database_version = 13;
let latest_database_version: u64;
// do not increment the db version if the user is not using sha256_media
if cfg!(feature = "sha256_media") {
latest_database_version = 14;
} else {
latest_database_version = 13;
}
if services().users.count()? > 0 {
// MIGRATIONS
@ -959,7 +966,7 @@ impl KeyValueDatabase {
}
}
services().globals.bump_database_version(13)?;
services().globals.bump_database_version(14)?;
warn!("Migration: 13 -> 14 finished");
} else {

View file

@ -17,7 +17,7 @@ use axum::{
extract::{DefaultBodyLimit, FromRequestParts, MatchedPath},
response::IntoResponse,
routing::{get, on, MethodFilter},
Router,
Json, Router,
};
use axum_server::{bind, bind_rustls, tls_rustls::RustlsConfig, Handle as ServerHandle};
use conduit::api::{client_server, server_server};
@ -38,6 +38,7 @@ use ruma::api::{
},
IncomingRequest,
};
use serde::Deserialize;
use tokio::{net::UnixListener, signal, sync::oneshot};
use tower::ServiceBuilder;
use tower_http::{
@ -214,7 +215,7 @@ async fn run_server() -> io::Result<()> {
let app: axum::routing::IntoMakeService<Router>;
if cfg!(feature = "zstd_compression") && config.zstd_compression == true {
if cfg!(feature = "zstd_compression") && config.zstd_compression {
debug!("zstd body compression is enabled");
app = routes()
.layer(middlewares.compression())
@ -489,6 +490,7 @@ fn routes() -> Router {
"/_matrix/client/v3/rooms/:room_id/initialSync",
get(initial_sync),
)
//.route("/client/server.json", get(syncv3_client_server_json))
.route("/", get(it_works))
.fallback(not_found)
}
@ -543,9 +545,22 @@ async fn initial_sync(_uri: Uri) -> impl IntoResponse {
}
async fn it_works() -> &'static str {
"Hello from Conduit!"
"hewwo from cowonduit woof!"
}
/*
// TODO: add /client/server.json support by querying our client well-known for the true matrix homeserver URL
async fn syncv3_client_server_json(uri: Uri) -> impl IntoResponse {
let server_name = services().globals.server_name().to_string();
let response = services().globals.default_client().get(&format!("https://{server_name"))
let server = uri.scheme_str().unwrap_or("https").to_owned() + "://" + uri.host().unwrap();
let version = format!("cowonduit {}", env!("CARGO_PKG_VERSION").to_owned());
let body = format!("{{\"server\":\"{server}\",\"version\":\"{version}\"}}");
Json(body)
}
*/
trait RouterExt {
fn ruma_route<H, T>(self, handler: H) -> Self
where

View file

@ -490,7 +490,7 @@ impl Service {
if self.unix_socket_path().is_some() {
match &self.unix_socket_path() {
Some(path) => {
std::fs::remove_file(path.to_owned()).unwrap();
std::fs::remove_file(path).unwrap();
}
None => error!(
"Unable to remove socket file at {:?} during shutdown.",

View file

@ -149,7 +149,9 @@ impl Service {
// TODO: Sort children
children_ids.reverse();
let chunk = self.get_room_chunk(sender_user, &current_room, children_pdus);
let chunk = self
.get_room_chunk(sender_user, &current_room, children_pdus)
.await;
if let Ok(chunk) = chunk {
if left_to_skip > 0 {
left_to_skip -= 1;
@ -303,7 +305,7 @@ impl Service {
})
}
fn get_room_chunk(
async fn get_room_chunk(
&self,
sender_user: &UserId,
room_id: &RoomId,

View file

@ -859,7 +859,7 @@ impl Service {
let target = pdu
.state_key()
.filter(|v| v.starts_with("@"))
.filter(|v| v.starts_with('@'))
.unwrap_or(sender.as_str());
let server_name = services().globals.server_name();
let server_user = format!("@conduit:{}", server_name);