@@ -9,25 +9,22 @@ use firestore::FirestoreDb;
9
9
use futures:: { stream:: FuturesUnordered , StreamExt } ;
10
10
use log:: info;
11
11
use tokio:: io:: AsyncReadExt ;
12
-
13
12
const CACHES_COLLECTION : & str = "caches" ;
14
-
15
13
#[ derive( Debug ) ]
16
14
pub struct MenuCache < ' a > {
17
15
cached_at : DateTime < Utc > ,
18
16
locations : Locations < ' a > ,
19
17
}
20
-
21
18
#[ derive( serde:: Serialize , serde:: Deserialize , Default ) ]
22
- struct InDbMenuCache {
19
+ struct GCloudMenuCache {
23
20
cached_at : DateTime < Utc > ,
24
21
data : Vec < u8 > ,
25
22
}
26
23
27
24
pub static REFRESH_INTERVAL : chrono:: Duration = chrono:: Duration :: minutes ( 15 ) ;
28
25
29
26
impl < ' a > MenuCache < ' a > {
30
- async fn from_async ( cache : InDbMenuCache ) -> Self {
27
+ async fn from_async ( cache : GCloudMenuCache ) -> Self {
31
28
if cache. data . is_empty ( ) {
32
29
return MenuCache {
33
30
cached_at : cache. cached_at ,
@@ -85,7 +82,7 @@ impl<'a> MenuCache<'a> {
85
82
86
83
async fn fetch_from_db ( ) -> Result < Self , crate :: error:: Error > {
87
84
let db = FirestoreDb :: new ( "ucsc-menu" ) . await ?;
88
- let cache: InDbMenuCache = db
85
+ let cache: GCloudMenuCache = db
89
86
. fluent ( )
90
87
. select ( )
91
88
. by_id_in ( CACHES_COLLECTION )
@@ -96,7 +93,7 @@ impl<'a> MenuCache<'a> {
96
93
Ok ( MenuCache :: from_async ( cache) . await )
97
94
}
98
95
99
- async fn to_db_representation ( & self ) -> InDbMenuCache {
96
+ async fn to_db_representation ( & self ) -> GCloudMenuCache {
100
97
let json = serde_json:: to_string ( self . locations ( ) ) . unwrap ( ) ;
101
98
let mut compressed = Vec :: with_capacity ( json. len ( ) / 4 ) ;
102
99
let mut compress =
@@ -105,14 +102,14 @@ impl<'a> MenuCache<'a> {
105
102
. read_buf ( & mut compressed)
106
103
. await
107
104
. expect ( "This should succeed" ) ;
108
- InDbMenuCache {
105
+ GCloudMenuCache {
109
106
cached_at : self . cached_at ,
110
107
data : compressed,
111
108
}
112
109
}
113
110
114
111
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 ;
116
113
let db = FirestoreDb :: new ( "ucsc-menu" ) . await ?;
117
114
db. fluent ( )
118
115
. update ( )
0 commit comments