From ac8ba338bb17a1af821cbf857c8b77e386b21841 Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Sun, 16 Jun 2019 21:45:13 +0200 Subject: [PATCH] Don't reuse cache struct Also we avoid converting from String into Cow<'a, str>' --- src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index ae755b7..71adfa5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ mod service; mod statics; use crate::{ - cache::{Cache, CacheState}, + cache::CacheState, error::{Error, Result}, service::{Bitbucket, FormService, GitHub, Gitlab, Service}, statics::{CLIENT, CSS, FAVICON, OPT, REPO_COUNT, VERSION_INFO}, @@ -56,6 +56,12 @@ struct State { cache: String, } +#[derive(Serialize)] +struct JsonResponse<'a> { + head: &'a str, + count: u64, +} + fn pull(path: impl AsRef) -> Result<()> { let repo = Repository::open_bare(path)?; let mut origin = repo.find_remote("origin")?; @@ -193,8 +199,8 @@ fn json_hoc( ) -> impl Future { let mapper = |r| match r { HocResult::NotFound => p404(), - HocResult::Hoc { hoc, head, .. } => Ok(HttpResponse::Ok().json(Cache { - head: head.into(), + HocResult::Hoc { hoc, head, .. } => Ok(HttpResponse::Ok().json(JsonResponse { + head: &head, count: hoc, })), };