Skip to content

Commit 0d780c7

Browse files
authored
fix: get_storage_timestamp/lock_for_read should ignore PRETOUCH_DT (#2067)
Closes STOR-484
1 parent 33d41fb commit 0d780c7

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

syncstorage-db/src/tests/batch.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,20 @@ async fn test_append_async_w_empty_string() -> Result<(), DbError> {
374374
})
375375
.await
376376
}
377+
378+
#[tokio::test]
379+
async fn pretouch() -> Result<(), DbError> {
380+
let settings = Settings::test_settings().syncstorage;
381+
with_test_transaction(settings, async |db: &mut dyn Db<Error = DbError>| {
382+
let uid = 1;
383+
let coll = "clients";
384+
db.delete_storage(hid(uid)).await?;
385+
let _batch = db.create_batch(cb(uid, coll, vec![])).await?;
386+
// client with no timestamp (or PRETOUCH on some backends) should act as if
387+
// no timestamp exists
388+
let ts = db.get_storage_timestamp(hid(uid)).await?;
389+
assert_eq!(ts, SyncTimestamp::zero());
390+
Ok(())
391+
})
392+
.await
393+
}

syncstorage-postgres/src/db/db_impl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl Db for PgDb {
9898
.select(user_collections::modified)
9999
.filter(user_collections::user_id.eq(user_id))
100100
.filter(user_collections::collection_id.eq(collection_id))
101+
.filter(user_collections::modified.gt(PRETOUCH_DT))
101102
.for_share()
102103
.first(&mut self.conn)
103104
.await
@@ -235,6 +236,7 @@ impl Db for PgDb {
235236
let modified = user_collections::table
236237
.select(max(user_collections::modified))
237238
.filter(user_collections::user_id.eq(params.legacy_id as i64))
239+
.filter(user_collections::modified.gt(PRETOUCH_DT))
238240
.first::<Option<_>>(&mut self.conn)
239241
.await?
240242
.unwrap_or_else(SyncTimestamp::zero);

0 commit comments

Comments
 (0)