File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed
syncstorage-postgres/src/db Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -112,8 +112,30 @@ impl Db for PgDb {
112112 async fn lock_for_write (
113113 & mut self ,
114114 params : params:: LockCollection ,
115- ) -> Result < results:: LockCollection , Self :: Error > {
116- todo ! ( )
115+ ) -> DbResult < results:: LockCollection > {
116+ let user_id = params. user_id . legacy_id as i64 ;
117+ let collection_id = self . get_or_create_collection_id ( & params. collection ) . await ?;
118+
119+ if let Some ( CollectionLock :: Read ) = self
120+ . session
121+ . coll_locks
122+ . get ( & ( user_id as u32 , collection_id) )
123+ {
124+ return Err ( DbError :: internal (
125+ "Can't escalate read-lock to write-lock" . to_string ( ) ,
126+ ) ) ;
127+ }
128+
129+ // Lock DB
130+ self . begin ( true ) . await ?;
131+ let modified = user_collections:: table
132+ . select ( user_collections:: modified)
133+ . filter ( user_collections:: fxa_uid. eq ( user_id) )
134+ . filter ( user_collections:: collection_id. eq ( collection_id) )
135+ . for_share ( )
136+ . first ( & mut self . conn )
137+ . await
138+ . optional ( ) ?;
117139 }
118140
119141 async fn get_collection_timestamps (
You can’t perform that action at this time.
0 commit comments