Skip to content

Commit

Permalink
feat: remove cache_response cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
kane50613 committed Dec 5, 2024
1 parent 6c7ceca commit 14fa1e5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ impl Database {
.unwrap()
}

pub async fn set(&self, key: u64, response: CacheResponse) {
pub async fn set(&self, key: u64, response: &CacheResponse) {
sqlx::query(
r#"INSERT OR REPLACE INTO cache (key, body, status, timestamp, content_type) VALUES (?, ?, ?, strftime('%s', 'now'), ?)"#,
).bind(
key as i64,
).bind(
response.body,
response.body.as_ref(),
).bind(
response.status,
).bind(
response.content_type,
response.content_type.as_ref(),
).execute(&self.connection)
.await.unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub async fn api_handler(request: Request) -> Response {
status: status.as_u16(),
};

DB.set(cache_key, cache_payload.clone()).await;
DB.set(cache_key, &cache_payload).await;

response_from_cache(cache_payload)
}
Expand Down

0 comments on commit 14fa1e5

Please sign in to comment.