Skip to content

Commit

Permalink
Remove unneded db model structs.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaj committed Jul 31, 2024
1 parent 2625d54 commit b0ef079
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on
* Improved item (image) sizing css. I hope it works in safari.
* Updated to `diesel` 2.1.0, `diesel-async` 0.3.2, and `ructe` 0.17.0.
* Uses std LazyLock (require rust 1.80) instead of `lazy_regex`.
* Removed unneded db model structs.
* Some more known kinds of places.


Expand Down
4 changes: 2 additions & 2 deletions src/fetch_places.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::models::PhotoPlace;
use crate::models::{Coord, Place};
use crate::schema::photo_places::dsl as pl;
use crate::schema::places::dsl as l;
Expand Down Expand Up @@ -107,9 +106,10 @@ impl OverpassOpt {
.await
.map_err(|e| Error::Db(image, e))?;
let q = pl::photo_places
.select(pl::place_id)
.filter(pl::photo_id.eq(image))
.filter(pl::place_id.eq(place.id));
if q.first::<PhotoPlace>(db).await.is_ok() {
if q.first::<i32>(db).await.is_ok() {
debug!(
"Photo #{} already has {} ({})",
image, place.id, place.place_name
Expand Down
19 changes: 0 additions & 19 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,6 @@ impl Facet for Tag {
}
}

#[derive(Debug, Clone, Queryable)]
pub struct PhotoTag {
pub id: i32,
pub photo_id: i32,
pub tag_id: i32,
}

#[derive(Debug, Clone, Queryable)]
pub struct Person {
pub id: i32,
Expand Down Expand Up @@ -327,12 +320,6 @@ impl Facet for Person {
}
}

#[derive(Debug, Clone, Queryable)]
pub struct PhotoPerson {
pub photo_id: i32,
pub person_id: i32,
}

#[derive(Debug, Clone, Queryable)]
pub struct Place {
pub id: i32,
Expand All @@ -352,12 +339,6 @@ impl Facet for Place {
}
}

#[derive(Debug, Clone, Queryable)]
pub struct PhotoPlace {
pub photo_id: i32,
pub place_id: i32,
}

#[derive(Debug, Clone, Identifiable, Queryable)]
pub struct Camera {
pub id: i32,
Expand Down
5 changes: 3 additions & 2 deletions src/server/admin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Admin-only views, generally called by javascript.
use super::error::ViewResult;
use super::{redirect_to_img, wrap, Context, Result, ViewError};
use crate::models::{Coord, Person, Photo, PhotoPerson, SizeTag, Tag};
use crate::models::{Coord, Person, Photo, SizeTag, Tag};
use crate::schema::photo_people::dsl as pp;
use crate::schema::photo_tags::dsl as pt;
use crate::schema::photos::dsl as p;
Expand Down Expand Up @@ -111,9 +111,10 @@ async fn set_person(context: Context, form: PersonForm) -> Result<Response> {
let mut c = context.db().await?;
let person = Person::get_or_create_name(&mut c, &form.person).await?;
let q = pp::photo_people
.select(pp::person_id)
.filter(pp::photo_id.eq(form.image))
.filter(pp::person_id.eq(person.id));
if q.first::<PhotoPerson>(&mut c).await.optional()?.is_some() {
if q.first::<i32>(&mut c).await.optional()?.is_some() {
info!("Photo #{} already has {:?}", form.image, person);
} else {
info!("Add {:?} on photo #{}!", person, form.image);
Expand Down

0 comments on commit b0ef079

Please sign in to comment.