Skip to content

Commit

Permalink
made sure that Location.* is not needlessly overfetched
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Jun 17, 2024
1 parent d4c9290 commit c96bf9b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 77 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/main-api/src/calendar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub async fn calendar_handler(
}

async fn get_location(pool: &PgPool, id: &str) -> Result<Option<Location>, sqlx::Error> {
sqlx::query_as!(Location, "SELECT * FROM de WHERE key = $1", id)
sqlx::query_as!(Location, "SELECT name,last_calendar_scrape_at,calendar_url,type,type_common_name,lat,lon FROM de WHERE key = $1", id)
.fetch_optional(pool)
.await
}
Expand Down
4 changes: 2 additions & 2 deletions server/main-api/src/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ async fn get_localised_data(
should_use_english: bool,
) -> Result<Location, HttpResponse> {
let result = if should_use_english {
sqlx::query_as!(Location, "SELECT * FROM en WHERE key = $1", id)
sqlx::query_as!(Location, "SELECT name,last_calendar_scrape_at,calendar_url,type,type_common_name,lat,lon FROM en WHERE key = $1", id)
.fetch_all(conn)
.await
} else {
sqlx::query_as!(Location, "SELECT * FROM de WHERE key = $1", id)
sqlx::query_as!(Location, "SELECT name,last_calendar_scrape_at,calendar_url,type,type_common_name,lat,lon FROM de WHERE key = $1", id)
.fetch_all(conn)
.await
};
Expand Down
4 changes: 0 additions & 4 deletions server/main-api/src/models.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use chrono::{DateTime, Utc};
use serde_json::Value;

#[derive(Debug, Clone)]
pub struct Location {
pub key: String,
pub name: String,
pub last_calendar_scrape_at: Option<DateTime<Utc>>,
pub tumonline_room_nr: Option<i32>,
pub calendar_url: Option<String>,
pub r#type: String,
pub type_common_name: String,
pub lat: f64,
pub lon: f64,
pub data: Value,
}

#[derive(Debug, Clone)]
Expand Down

0 comments on commit c96bf9b

Please sign in to comment.