@@ -43,7 +43,7 @@ impl Db for MysqlDb {
4343 // Lock the db
4444 self . begin ( false ) . await ?;
4545 let collection_id = self
46- . get_collection_id ( & params. collection )
46+ . _get_collection_id ( & params. collection )
4747 . await
4848 . or_else ( |e| {
4949 if e. is_collection_not_found ( ) {
@@ -165,7 +165,7 @@ impl Db for MysqlDb {
165165 params : params:: DeleteCollection ,
166166 ) -> DbResult < SyncTimestamp > {
167167 let user_id = params. user_id . legacy_id as i64 ;
168- let collection_id = self . get_collection_id ( & params. collection ) . await ?;
168+ let collection_id = self . _get_collection_id ( & params. collection ) . await ?;
169169 let mut count = delete ( bso:: table)
170170 . filter ( bso:: user_id. eq ( user_id) )
171171 . filter ( bso:: collection_id. eq ( & collection_id) )
@@ -184,28 +184,6 @@ impl Db for MysqlDb {
184184 self . get_storage_timestamp ( params. user_id ) . await
185185 }
186186
187- async fn get_collection_id ( & mut self , name : & str ) -> DbResult < i32 > {
188- if let Some ( id) = self . coll_cache . get_id ( name) ? {
189- return Ok ( id) ;
190- }
191-
192- let id = sql_query (
193- "SELECT id
194- FROM collections
195- WHERE name = ?" ,
196- )
197- . bind :: < Text , _ > ( name)
198- . get_result :: < IdResult > ( & mut self . conn )
199- . await
200- . optional ( ) ?
201- . ok_or_else ( DbError :: collection_not_found) ?
202- . id ;
203- if !self . session . in_write_transaction {
204- self . coll_cache . put ( id, name. to_owned ( ) ) ?;
205- }
206- Ok ( id)
207- }
208-
209187 async fn put_bso ( & mut self , bso : params:: PutBso ) -> DbResult < results:: PutBso > {
210188 /*
211189 if bso.payload.is_none() && bso.sortindex.is_none() && bso.ttl.is_none() {
@@ -223,7 +201,6 @@ impl Db for MysqlDb {
223201 . get_quota_usage ( params:: GetQuotaUsage {
224202 user_id : bso. user_id . clone ( ) ,
225203 collection : bso. collection . clone ( ) ,
226- collection_id,
227204 } )
228205 . await ?;
229206 if usage. total_bytes >= self . quota . size {
@@ -311,7 +288,7 @@ impl Db for MysqlDb {
311288
312289 async fn get_bsos ( & mut self , params : params:: GetBsos ) -> DbResult < results:: GetBsos > {
313290 let user_id = params. user_id . legacy_id as i64 ;
314- let collection_id = self . get_collection_id ( & params. collection ) . await ?;
291+ let collection_id = self . _get_collection_id ( & params. collection ) . await ?;
315292 let now = self . session . timestamp . as_i64 ( ) ;
316293 let mut query = bso:: table
317294 . select ( (
@@ -412,7 +389,7 @@ impl Db for MysqlDb {
412389
413390 async fn get_bso_ids ( & mut self , params : params:: GetBsos ) -> DbResult < results:: GetBsoIds > {
414391 let user_id = params. user_id . legacy_id as i64 ;
415- let collection_id = self . get_collection_id ( & params. collection ) . await ?;
392+ let collection_id = self . _get_collection_id ( & params. collection ) . await ?;
416393 let mut query = bso:: table
417394 . select ( bso:: id)
418395 . filter ( bso:: user_id. eq ( user_id) )
@@ -475,7 +452,7 @@ impl Db for MysqlDb {
475452
476453 async fn get_bso ( & mut self , params : params:: GetBso ) -> DbResult < Option < results:: GetBso > > {
477454 let user_id = params. user_id . legacy_id as i64 ;
478- let collection_id = self . get_collection_id ( & params. collection ) . await ?;
455+ let collection_id = self . _get_collection_id ( & params. collection ) . await ?;
479456 Ok ( bso:: table
480457 . select ( (
481458 bso:: id,
@@ -495,7 +472,7 @@ impl Db for MysqlDb {
495472
496473 async fn delete_bso ( & mut self , params : params:: DeleteBso ) -> DbResult < results:: DeleteBso > {
497474 let user_id = params. user_id . legacy_id ;
498- let collection_id = self . get_collection_id ( & params. collection ) . await ?;
475+ let collection_id = self . _get_collection_id ( & params. collection ) . await ?;
499476 let affected_rows = delete ( bso:: table)
500477 . filter ( bso:: user_id. eq ( user_id as i64 ) )
501478 . filter ( bso:: collection_id. eq ( & collection_id) )
@@ -516,7 +493,7 @@ impl Db for MysqlDb {
516493
517494 async fn delete_bsos ( & mut self , params : params:: DeleteBsos ) -> DbResult < results:: DeleteBsos > {
518495 let user_id = params. user_id . legacy_id as i64 ;
519- let collection_id = self . get_collection_id ( & params. collection ) . await ?;
496+ let collection_id = self . _get_collection_id ( & params. collection ) . await ?;
520497 delete ( bso:: table)
521498 . filter ( bso:: user_id. eq ( user_id) )
522499 . filter ( bso:: collection_id. eq ( & collection_id) )
@@ -572,7 +549,7 @@ impl Db for MysqlDb {
572549 params : params:: GetCollectionTimestamp ,
573550 ) -> DbResult < SyncTimestamp > {
574551 let user_id = params. user_id . legacy_id as u32 ;
575- let collection_id = self . get_collection_id ( & params. collection ) . await ?;
552+ let collection_id = self . _get_collection_id ( & params. collection ) . await ?;
576553 if let Some ( modified) = self
577554 . session
578555 . coll_modified_cache
@@ -595,7 +572,7 @@ impl Db for MysqlDb {
595572 params : params:: GetBsoTimestamp ,
596573 ) -> DbResult < SyncTimestamp > {
597574 let user_id = params. user_id . legacy_id as i64 ;
598- let collection_id = self . get_collection_id ( & params. collection ) . await ?;
575+ let collection_id = self . _get_collection_id ( & params. collection ) . await ?;
599576 let modified = bso:: table
600577 . select ( bso:: modified)
601578 . filter ( bso:: user_id. eq ( user_id) )
@@ -705,13 +682,14 @@ impl Db for MysqlDb {
705682 params : params:: GetQuotaUsage ,
706683 ) -> DbResult < results:: GetQuotaUsage > {
707684 let uid = params. user_id . legacy_id as i64 ;
685+ let collection_id = self . _get_collection_id ( & params. collection ) . await ?;
708686 let ( total_bytes, count) : ( i64 , i32 ) = user_collections:: table
709687 . select ( (
710688 sql :: < BigInt > ( "COALESCE(SUM(COALESCE(total_bytes, 0)), 0)" ) ,
711689 sql :: < Integer > ( "COALESCE(SUM(COALESCE(count, 0)), 0)" ) ,
712690 ) )
713691 . filter ( user_collections:: user_id. eq ( uid) )
714- . filter ( user_collections:: collection_id. eq ( params . collection_id ) )
692+ . filter ( user_collections:: collection_id. eq ( collection_id) )
715693 . get_result ( & mut self . conn )
716694 . await
717695 . optional ( ) ?
@@ -769,6 +747,11 @@ impl Db for MysqlDb {
769747 self . _create_collection ( name) . await
770748 }
771749
750+ #[ cfg( debug_assertions) ]
751+ async fn get_collection_id ( & mut self , name : & str ) -> DbResult < i32 > {
752+ self . _get_collection_id ( name) . await
753+ }
754+
772755 #[ cfg( debug_assertions) ]
773756 fn timestamp ( & self ) -> SyncTimestamp {
774757 self . session . timestamp
@@ -795,12 +778,6 @@ impl Db for MysqlDb {
795778 }
796779}
797780
798- #[ derive( Debug , QueryableByName ) ]
799- struct IdResult {
800- #[ diesel( sql_type = Integer ) ]
801- id : i32 ,
802- }
803-
804781#[ derive( Debug , QueryableByName ) ]
805782struct UserCollectionsResult {
806783 // Can't substitute column names here.
0 commit comments