@@ -9,25 +9,22 @@ use firestore::FirestoreDb;
99use futures:: { stream:: FuturesUnordered , StreamExt } ;
1010use log:: info;
1111use tokio:: io:: AsyncReadExt ;
12-
1312const CACHES_COLLECTION : & str = "caches" ;
14-
1513#[ derive( Debug ) ]
1614pub struct MenuCache < ' a > {
1715 cached_at : DateTime < Utc > ,
1816 locations : Locations < ' a > ,
1917}
20-
2118#[ derive( serde:: Serialize , serde:: Deserialize , Default ) ]
22- struct InDbMenuCache {
19+ struct GCloudMenuCache {
2320 cached_at : DateTime < Utc > ,
2421 data : Vec < u8 > ,
2522}
2623
2724pub static REFRESH_INTERVAL : chrono:: Duration = chrono:: Duration :: minutes ( 15 ) ;
2825
2926impl < ' a > MenuCache < ' a > {
30- async fn from_async ( cache : InDbMenuCache ) -> Self {
27+ async fn from_async ( cache : GCloudMenuCache ) -> Self {
3128 if cache. data . is_empty ( ) {
3229 return MenuCache {
3330 cached_at : cache. cached_at ,
@@ -85,7 +82,7 @@ impl<'a> MenuCache<'a> {
8582
8683 async fn fetch_from_db ( ) -> Result < Self , crate :: error:: Error > {
8784 let db = FirestoreDb :: new ( "ucsc-menu" ) . await ?;
88- let cache: InDbMenuCache = db
85+ let cache: GCloudMenuCache = db
8986 . fluent ( )
9087 . select ( )
9188 . by_id_in ( CACHES_COLLECTION )
@@ -96,7 +93,7 @@ impl<'a> MenuCache<'a> {
9693 Ok ( MenuCache :: from_async ( cache) . await )
9794 }
9895
99- async fn to_db_representation ( & self ) -> InDbMenuCache {
96+ async fn to_db_representation ( & self ) -> GCloudMenuCache {
10097 let json = serde_json:: to_string ( self . locations ( ) ) . unwrap ( ) ;
10198 let mut compressed = Vec :: with_capacity ( json. len ( ) / 4 ) ;
10299 let mut compress =
@@ -105,14 +102,14 @@ impl<'a> MenuCache<'a> {
105102 . read_buf ( & mut compressed)
106103 . await
107104 . expect ( "This should succeed" ) ;
108- InDbMenuCache {
105+ GCloudMenuCache {
109106 cached_at : self . cached_at ,
110107 data : compressed,
111108 }
112109 }
113110
114111 async fn save_to_db ( & self ) -> Result < ( ) , firestore:: errors:: FirestoreError > {
115- let cache: InDbMenuCache = self . to_db_representation ( ) . await ;
112+ let cache: GCloudMenuCache = self . to_db_representation ( ) . await ;
116113 let db = FirestoreDb :: new ( "ucsc-menu" ) . await ?;
117114 db. fluent ( )
118115 . update ( )
0 commit comments