Skip to content

Commit

Permalink
Collect performance data for v3 elements endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Oct 29, 2024
1 parent 542b450 commit 45b6796
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/element/v3.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::element::Element;
use crate::log::RequestExtension;
use crate::osm::overpass::OverpassElement;
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 @@ -65,15 +68,22 @@ impl Into<Json<GetItem>> for Element {
}

#[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 elements = pool
.get()
.await?
.interact(move |conn| {
Element::select_updated_since(&args.updated_since, Some(args.limit), conn)
})
.await??;
Ok(Json(elements.into_iter().map(|it| it.into()).collect()))
let res: Json<Vec<GetItem>> = Json(elements.into_iter().map(|it| it.into()).collect());
req.extensions_mut()
.insert(RequestExtension::new("v3/elements", res.len() as i64));
Ok(res)
}

#[get("{id}")]
Expand Down
40 changes: 40 additions & 0 deletions src/rpc/handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use super::get_area::get_area;
use crate::Result;
use actix_web::{
post,
web::{Data, Json, Query},
HttpRequest, HttpResponse, Responder,
};
use deadpool_sqlite::Pool;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::sync::Arc;

#[derive(Deserialize, Clone)]
struct RequestBody {
jsonrpc: String,
method: String,
params: Value,
id: Value,
}

#[derive(Serialize)]
struct ResponseBody {}

#[post("/")]
pub async fn handle(
req: HttpRequest,
body: Query<RequestBody>,
pool: Data<Arc<Pool>>,
) -> Result<Json<ResponseBody>> {
let cloned_body = body.clone();
let res = pool
.get()
.await?
.interact(move |_| match cloned_body.method.as_str() {
"get_area" => ResponseBody {},
_ => ResponseBody {},
})
.await?;
Ok(Json(res))
}

0 comments on commit 45b6796

Please sign in to comment.