Skip to content

Commit

Permalink
Collect performance data for all v3 endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Oct 30, 2024
1 parent 003a7c2 commit 861653d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/area/v3.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::area::Area;
use crate::log::RequestExtension;
use crate::Error;
use actix_web::get;
use actix_web::web::Data;
use actix_web::web::Json;
use actix_web::web::Path;
use actix_web::web::Query;
use actix_web::HttpMessage;
use actix_web::HttpRequest;
use deadpool_sqlite::Pool;
use serde::Deserialize;
use serde::Serialize;
Expand Down Expand Up @@ -56,14 +59,20 @@ impl Into<Json<GetItem>> for Area {
}

#[get("")]
pub async fn get(args: Query<GetArgs>, pool: Data<Arc<Pool>>) -> Result<Json<Vec<GetItem>>, Error> {
pub async fn get(
req: HttpRequest,
args: Query<GetArgs>,
pool: Data<Arc<Pool>>,
) -> Result<Json<Vec<GetItem>>, Error> {
let areas = pool
.get()
.await?
.interact(move |conn| {
Area::select_updated_since(&args.updated_since, Some(args.limit), conn)
})
.await??;
req.extensions_mut()
.insert(RequestExtension::new("v3/areas", areas.len() as i64));
Ok(Json(areas.into_iter().map(|it| it.into()).collect()))
}

Expand Down
19 changes: 15 additions & 4 deletions src/area_element/v3.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::model::AreaElement;
use crate::{Error, Result};
use crate::{log::RequestExtension, Error, Result};
use actix_web::{
get,
web::{Data, Json, Path, Query},
HttpMessage, HttpRequest,
};
use deadpool_sqlite::Pool;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -58,15 +59,25 @@ impl Into<Json<GetItem>> for AreaElement {
}

#[get("")]
pub async fn get(args: Query<GetArgs>, pool: Data<Arc<Pool>>) -> Result<Json<Vec<GetItem>>> {
let areas = pool
pub async fn get(
req: HttpRequest,
args: Query<GetArgs>,
pool: Data<Arc<Pool>>,
) -> Result<Json<Vec<GetItem>>> {
let area_elements = pool
.get()
.await?
.interact(move |conn| {
AreaElement::select_updated_since(&args.updated_since, Some(args.limit), conn)
})
.await??;
Ok(Json(areas.into_iter().map(|it| it.into()).collect()))
req.extensions_mut().insert(RequestExtension::new(
"v3/area-elements",
area_elements.len() as i64,
));
Ok(Json(
area_elements.into_iter().map(|it| it.into()).collect(),
))
}

#[get("{id}")]
Expand Down
19 changes: 16 additions & 3 deletions src/element_comment/v3.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use super::ElementComment;
use crate::log::RequestExtension;
use crate::Error;
use actix_web::get;
use actix_web::web::Data;
use actix_web::web::Json;
use actix_web::web::Path;
use actix_web::web::Query;
use actix_web::HttpMessage;
use actix_web::HttpRequest;
use deadpool_sqlite::Pool;
use serde::Deserialize;
use serde::Serialize;
Expand Down Expand Up @@ -71,15 +74,25 @@ impl Into<Json<GetItem>> for ElementComment {
}

#[get("")]
pub async fn get(args: Query<GetArgs>, pool: Data<Arc<Pool>>) -> Result<Json<Vec<GetItem>>, Error> {
let areas = pool
pub async fn get(
req: HttpRequest,
args: Query<GetArgs>,
pool: Data<Arc<Pool>>,
) -> Result<Json<Vec<GetItem>>, Error> {
let element_comments = pool
.get()
.await?
.interact(move |conn| {
ElementComment::select_updated_since(&args.updated_since, Some(args.limit), conn)
})
.await??;
Ok(Json(areas.into_iter().map(|it| it.into()).collect()))
req.extensions_mut().insert(RequestExtension::new(
"v3/element-comments",
element_comments.len() as i64,
));
Ok(Json(
element_comments.into_iter().map(|it| it.into()).collect(),
))
}

#[get("{id}")]
Expand Down
11 changes: 10 additions & 1 deletion src/event/v3.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use super::Event;
use crate::log::RequestExtension;
use crate::Error;
use actix_web::get;
use actix_web::web::Data;
use actix_web::web::Json;
use actix_web::web::Path;
use actix_web::web::Query;
use actix_web::HttpMessage;
use actix_web::HttpRequest;
use deadpool_sqlite::Pool;
use serde::Deserialize;
use serde::Serialize;
Expand Down Expand Up @@ -96,7 +99,11 @@ impl Into<Json<GetItem>> for Event {
}

#[get("")]
pub async fn get(args: Query<GetArgs>, pool: Data<Arc<Pool>>) -> Result<Json<Vec<GetItem>>, Error> {
pub async fn get(
req: HttpRequest,
args: Query<GetArgs>,
pool: Data<Arc<Pool>>,
) -> Result<Json<Vec<GetItem>>, Error> {
let events = pool
.get()
.await?
Expand All @@ -107,6 +114,8 @@ pub async fn get(args: Query<GetArgs>, pool: Data<Arc<Pool>>) -> Result<Json<Vec
None => Event::select_all(Some("DESC".into()), Some(args.limit.unwrap_or(100)), conn),
})
.await??;
req.extensions_mut()
.insert(RequestExtension::new("v3/events", events.len() as i64));
Ok(Json(events.into_iter().map(|it| it.into()).collect()))
}

Expand Down
11 changes: 10 additions & 1 deletion src/report/v3.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use super::Report;
use crate::log::RequestExtension;
use crate::Error;
use actix_web::get;
use actix_web::web::Data;
use actix_web::web::Json;
use actix_web::web::Path;
use actix_web::web::Query;
use actix_web::HttpMessage;
use actix_web::HttpRequest;
use deadpool_sqlite::Pool;
use serde::Deserialize;
use serde::Serialize;
Expand Down Expand Up @@ -72,14 +75,20 @@ impl Into<Json<GetItem>> for Report {
}

#[get("")]
pub async fn get(args: Query<GetArgs>, pool: Data<Arc<Pool>>) -> Result<Json<Vec<GetItem>>, Error> {
pub async fn get(
req: HttpRequest,
args: Query<GetArgs>,
pool: Data<Arc<Pool>>,
) -> Result<Json<Vec<GetItem>>, Error> {
let reports = pool
.get()
.await?
.interact(move |conn| {
Report::select_updated_since(&args.updated_since, Some(args.limit), conn)
})
.await??;
req.extensions_mut()
.insert(RequestExtension::new("v3/reports", reports.len() as i64));
Ok(Json(reports.into_iter().map(|it| it.into()).collect()))
}

Expand Down
11 changes: 10 additions & 1 deletion src/user/v3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::log::RequestExtension;
use crate::osm::osm::OsmUser;
use crate::user::User;
use crate::Error;
Expand All @@ -6,6 +7,8 @@ use actix_web::web::Data;
use actix_web::web::Json;
use actix_web::web::Path;
use actix_web::web::Query;
use actix_web::HttpMessage;
use actix_web::HttpRequest;
use deadpool_sqlite::Pool;
use serde::Deserialize;
use serde::Serialize;
Expand Down Expand Up @@ -65,14 +68,20 @@ impl Into<Json<GetItem>> for User {
}

#[get("")]
pub async fn get(args: Query<GetArgs>, pool: Data<Arc<Pool>>) -> Result<Json<Vec<GetItem>>, Error> {
pub async fn get(
req: HttpRequest,
args: Query<GetArgs>,
pool: Data<Arc<Pool>>,
) -> Result<Json<Vec<GetItem>>, Error> {
let users = pool
.get()
.await?
.interact(move |conn| {
User::select_updated_since(&args.updated_since, Some(args.limit), conn)
})
.await??;
req.extensions_mut()
.insert(RequestExtension::new("v3/users", users.len() as i64));
Ok(Json(users.into_iter().map(|it| it.into()).collect()))
}

Expand Down

0 comments on commit 861653d

Please sign in to comment.