Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.

Commit 2ce2ecd

Browse files
committed
update dependencies
1 parent 08c3b85 commit 2ce2ecd

File tree

7 files changed

+51
-45
lines changed

7 files changed

+51
-45
lines changed

Cargo.lock

Lines changed: 20 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ dotenvy = "0.15.7"
1414
rustis = "0.13.3"
1515
serde = { version = "1.0.218", features = ["derive"] }
1616
serde_json = { version = "1.0.140", features = ["preserve_order"] }
17-
tokio = { version = "1.43.0", features = ["full"] }
17+
tokio = { version = "1.43.0", features = ["rt-multi-thread"] }
1818
utoipa = { version = "5.3.1", features = ["axum_extras", "preserve_order", "chrono"] }
1919
utoipa-axum = "0.2.0"
2020
chrono = { version = "0.4.40", features = ["serde"] }
2121
indexmap = { version = "2.7.1", features = ["serde"] }
2222
tower-http = { version = "0.6.2", features = ["catch-panic", "trace", "cors", "normalize-path"] }
23-
sentry = { version = "0.36.0", default-features = false, features = ["rustls", "reqwest", "backtrace", "contexts", "debug-images", "panic"] }
23+
sentry = { version = "0.37.0", default-features = false, features = ["rustls", "reqwest", "backtrace", "contexts", "debug-images", "panic"] }
2424
tracing = "0.1.41"
2525
reqwest = { version = "0.12.12", default-features = false, features = ["json", "rustls-tls"] }
2626
nestify = "0.3.3"
2727
sha2 = "0.10.8"
28-
sentry-tower = { version = "0.36.0", features = ["http", "axum-matched-path"] }
28+
sentry-tower = { version = "0.37.0", features = ["http", "axum-matched-path"] }
2929
sha1 = "0.10.6"
3030
tower = "0.5.2"

src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Cache {
6161
instance
6262
}
6363

64-
#[inline(always)]
64+
#[inline]
6565
pub async fn cached<T, F, Fut>(&self, key: &str, ttl: u64, fn_compute: F) -> T
6666
where
6767
T: Serialize + DeserializeOwned,

src/database.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ impl Database {
8181
instance
8282
}
8383

84-
#[inline(always)]
84+
#[inline]
8585
pub fn write(&self) -> &sqlx::PgPool {
8686
&self.write
8787
}
8888

89-
#[inline(always)]
89+
#[inline]
9090
pub fn read(&self) -> &sqlx::PgPool {
9191
self.read.as_ref().unwrap_or(&self.write)
9292
}

src/logger.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub enum LoggerLevel {
55
Error,
66
}
77

8+
#[inline]
89
pub fn log(level: LoggerLevel, message: String) {
910
let level = match level {
1011
LoggerLevel::Info => " INF ".on_blue(),

src/models.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl Author {
5151
}
5252
}
5353

54+
#[inline]
5455
pub async fn by_key(database: &crate::database::Database, key: &str) -> Option<Self> {
5556
let row = sqlx::query(&format!(
5657
"SELECT {} FROM authors WHERE authors.key = $1",
@@ -194,6 +195,7 @@ impl Extension {
194195
}
195196
}
196197

198+
#[inline]
197199
pub async fn all(database: &crate::database::Database) -> Result<Vec<Self>, sqlx::Error> {
198200
let rows = sqlx::query(&format!(
199201
r#"
@@ -213,6 +215,7 @@ impl Extension {
213215
Ok(rows.into_iter().map(Self::map).collect())
214216
}
215217

218+
#[inline]
216219
pub async fn by_id(database: &crate::database::Database, id: i32) -> Option<Self> {
217220
let row = sqlx::query(&format!(
218221
r#"
@@ -234,6 +237,7 @@ impl Extension {
234237
row.map(Self::map)
235238
}
236239

240+
#[inline]
237241
pub async fn by_identifier(
238242
database: &crate::database::Database,
239243
identifier: &str,

src/telemetry.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use rustis::commands::{ExpireOption, GenericCommands, StringCommands};
33
use serde::{Deserialize, Serialize};
44
use sha2::Digest;
55
use sqlx::types::Uuid;
6-
use std::{collections::HashMap, sync::Arc};
6+
use std::{
7+
collections::{HashMap, HashSet},
8+
sync::Arc,
9+
};
710
use tokio::sync::Mutex;
811

912
nestify::nest! {
@@ -70,6 +73,8 @@ pub struct TelemetryLogger {
7073
database: Arc<crate::database::Database>,
7174
cache: Arc<crate::cache::Cache>,
7275
env: Arc<crate::env::Env>,
76+
77+
client: reqwest::Client,
7378
}
7479

7580
impl TelemetryLogger {
@@ -83,9 +88,15 @@ impl TelemetryLogger {
8388
database,
8489
cache,
8590
env,
91+
92+
client: reqwest::Client::builder()
93+
.user_agent("Blueprint API https://blueprint.zip")
94+
.build()
95+
.unwrap(),
8696
}
8797
}
8898

99+
#[inline]
89100
pub async fn log(&self, ip: &str, telemetry: TelemetryData) -> Option<()> {
90101
let mut processing = self.processing.lock().await;
91102

@@ -119,13 +130,14 @@ impl TelemetryLogger {
119130
Some(())
120131
}
121132

122-
async fn lookup_ips(&self, ips: &[&str]) -> HashMap<String, (String, String)> {
133+
#[inline]
134+
async fn lookup_ips(&self, ips: &[&str]) -> HashMap<String, [String; 2]> {
123135
let mut result = HashMap::new();
124136

125-
let data = reqwest::Client::new()
137+
let data = self
138+
.client
126139
.post("http://ip-api.com/batch")
127140
.header("Content-Type", "application/json")
128-
.header("User-Agent", "Blueprint API/1.0.0 https://blueprint.zip")
129141
.json(
130142
&ips.iter()
131143
.map(|ip| {
@@ -134,7 +146,7 @@ impl TelemetryLogger {
134146
"fields": "continentCode,countryCode,query"
135147
})
136148
})
137-
.collect::<Vec<_>>(),
149+
.collect::<HashSet<_>>(),
138150
)
139151
.send()
140152
.await
@@ -150,10 +162,10 @@ impl TelemetryLogger {
150162

151163
result.insert(
152164
entry["query"].as_str().unwrap().to_string(),
153-
(
165+
[
154166
entry["continentCode"].as_str().unwrap().to_string(),
155167
entry["countryCode"].as_str().unwrap().to_string(),
156-
),
168+
],
157169
);
158170
}
159171

@@ -183,7 +195,7 @@ impl TelemetryLogger {
183195
.await;
184196

185197
for t in telemetry.iter_mut() {
186-
if let Some((continent, country)) = ips.get(&t.ip) {
198+
if let Some([continent, country]) = ips.get(&t.ip) {
187199
t.continent = Some(continent.clone());
188200
t.country = Some(country.clone());
189201
}

0 commit comments

Comments
 (0)