|
|
@@ -154,6 +154,12 @@ func (h *SessionHandler) CreateSession(c *gin.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Events belong to the session's sync unit, so advance its timestamp
|
|
|
+ // after all event upserts/deletions have completed.
|
|
|
+ if err := tx.Model(&session).Update("updated_at", gorm.Expr("NOW()")).Error; err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
return nil
|
|
|
})
|
|
|
if isConflict {
|
|
|
@@ -240,7 +246,10 @@ func (h *SessionHandler) AddEventToSession(c *gin.Context) {
|
|
|
respondError(c, http.StatusInternalServerError, 500, "failed to add event")
|
|
|
return
|
|
|
}
|
|
|
- h.DB.Model(&session).Updates(map[string]interface{}{"revision": gorm.Expr("revision + 1")})
|
|
|
+ h.DB.Model(&session).Updates(map[string]interface{}{
|
|
|
+ "revision": gorm.Expr("revision + 1"),
|
|
|
+ "updated_at": gorm.Expr("NOW()"),
|
|
|
+ })
|
|
|
respondSuccess(c, event)
|
|
|
}
|
|
|
|
|
|
@@ -251,7 +260,11 @@ func (h *SessionHandler) DeleteSession(c *gin.Context) {
|
|
|
now := time.Now().UTC()
|
|
|
result := h.DB.Model(&models.CelestiaSession{}).
|
|
|
Where("id = ? AND user_id = ? AND deleted_at IS NULL", sessionID, userID).
|
|
|
- Updates(map[string]interface{}{"deleted_at": &now, "revision": gorm.Expr("revision + 1")})
|
|
|
+ Updates(map[string]interface{}{
|
|
|
+ "deleted_at": &now,
|
|
|
+ "revision": gorm.Expr("revision + 1"),
|
|
|
+ "updated_at": gorm.Expr("NOW()"),
|
|
|
+ })
|
|
|
if result.Error != nil {
|
|
|
respondError(c, http.StatusInternalServerError, 500, "failed to delete record")
|
|
|
return
|