fix: Revert "fix: mysql: Call set_timestamp in lock_for_write_sync."

This reverts commit d6c0b9efc68111d6a433e7b618dde789ba5377d6.
This commit is contained in:
Philip Jenvey 2025-08-26 12:08:47 -07:00
parent 44148da7c8
commit dfe216466d
No known key found for this signature in database
GPG Key ID: 5B9F83DE4F7EB7FA

View File

@ -212,36 +212,24 @@ impl MysqlDb {
// Lock the db
self.begin(true)?;
// SyncTimestamp only has 10 ms resolution.
let result = user_collections::table
.select((
sql::<BigInt>("UNIX_TIMESTAMP(UTC_TIMESTAMP(2))*1000"),
user_collections::modified,
))
let modified = user_collections::table
.select(user_collections::modified)
.filter(user_collections::user_id.eq(user_id))
.filter(user_collections::collection_id.eq(collection_id))
.for_update()
.first(&mut *self.conn.write()?)
.optional()?;
let timestamp = if let Some((timestamp, modified)) = result {
if let Some(modified) = modified {
let modified = SyncTimestamp::from_i64(modified)?;
let now = SyncTimestamp::from_i64(timestamp)?;
// Forbid the write if it would not properly incr the timestamp
if modified >= now {
if modified >= self.timestamp() {
return Err(DbError::conflict());
}
self.session
.borrow_mut()
.coll_modified_cache
.insert((user_id as u32, collection_id), modified);
now
} else {
let result = sql_query("SELECT UNIX_TIMESTAMP(UTC_TIMESTAMP(2))*1000 AS timestamp")
.get_result::<TimestampResult>(&mut *self.conn.write()?)?;
SyncTimestamp::from_i64(result.timestamp)?
};
self.set_timestamp(timestamp);
}
self.session
.borrow_mut()
.coll_locks
@ -1155,12 +1143,6 @@ struct NameResult {
name: String,
}
#[derive(Debug, QueryableByName)]
struct TimestampResult {
#[diesel(sql_type = BigInt)]
timestamp: i64,
}
#[derive(Debug, QueryableByName)]
struct UserCollectionsResult {
// Can't substitute column names here.