Skip to content

Commit

Permalink
fix: geofence lookup & optimize paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jul 30, 2023
1 parent ec44745 commit 4b4bb7e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions server/model/src/db/geofence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,11 @@ impl Query {
) -> Result<PaginateResults<Vec<Json>>, DbErr> {
let column = Column::from_str(&args.sort_by).unwrap_or(Column::Name);

let mut paginator = Entity::find()
.order_by(column, parse_order(&args.order))
.filter(Column::Name.like(format!("%{}%", args.q).as_str()));
let mut paginator = Entity::find().order_by(column, parse_order(&args.order));

if args.q.len() > 0 {
paginator = paginator.filter(Column::Name.like(format!("%{}%", args.q).as_str()));
}
if let Some(parent) = args.parent {
paginator = if parent == 0 {
paginator.filter(Column::Parent.is_null())
Expand Down Expand Up @@ -585,9 +586,17 @@ impl Query {
/// Updates or creates a Geofence model, returns a model struct
pub async fn upsert(db: &DatabaseConnection, id: u32, json: Json) -> Result<Model, ModelError> {
let mut json = json;
let old_model = Entity::find_by_id(id).one(db).await?;

let mut new_model = json.to_geofence()?;

let old_model = if id == 0 {
Query::get_one(db, new_model.name.clone().unwrap())
.await
.ok()
} else {
Entity::find_by_id(id).one(db).await?
};

let name = new_model.name.as_ref();

let model = if let Some(old_model) = old_model {
Expand Down

1 comment on commit 4b4bb7e

@vercel
Copy link

@vercel vercel bot commented on 4b4bb7e Jul 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

koji – ./

koji-turtiesocks.vercel.app
koji-git-main-turtiesocks.vercel.app
koji.vercel.app

Please sign in to comment.