diff --git a/server/backend/database/memory/database.go b/server/backend/database/memory/database.go index 08b2b1364..f778c5e6a 100644 --- a/server/backend/database/memory/database.go +++ b/server/backend/database/memory/database.go @@ -746,6 +746,7 @@ func (d *DB) FindDocInfoByKeyAndOwner( Owner: clientRefKey.ClientID, ServerSeq: 0, CreatedAt: now, + UpdatedAt: now, AccessedAt: now, } if err := txn.Insert(tblDocuments, info); err != nil { diff --git a/server/backend/database/mongo/client.go b/server/backend/database/mongo/client.go index 3d65ff029..7e8daca79 100644 --- a/server/backend/database/mongo/client.go +++ b/server/backend/database/mongo/client.go @@ -739,8 +739,9 @@ func (c *Client) FindDocInfoByKeyAndOwner( "owner": clientRefKey.ClientID, "server_seq": 0, "created_at": now, + "updated_at": now, }, - }) + }, options.FindOneAndUpdate().SetReturnDocument(options.After)) } else { result = c.collection(ColDocuments).FindOne(ctx, filter) if result.Err() == mongo.ErrNoDocuments { diff --git a/server/backend/database/testcases/testcases.go b/server/backend/database/testcases/testcases.go index 06a54bd20..1dc9212e9 100644 --- a/server/backend/database/testcases/testcases.go +++ b/server/backend/database/testcases/testcases.go @@ -948,6 +948,9 @@ func RunCreateChangeInfosTest(t *testing.T, db database.Database, projectID type // 01. Create a client and a document then attach the document to the client. clientInfo, _ := db.ActivateClient(ctx, projectID, t.Name()) docInfo1, _ := db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), docKey, true) + assert.Equal(t, docInfo1.Owner, clientInfo.ID) + assert.NotEqual(t, gotime.Date(1, gotime.January, 1, 0, 0, 0, 0, gotime.UTC), docInfo1.UpdatedAt) + assert.Equal(t, docInfo1.CreatedAt, docInfo1.UpdatedAt) docRefKey := docInfo1.RefKey() assert.NoError(t, clientInfo.AttachDocument(docRefKey.DocID, false)) assert.NoError(t, db.UpdateClientInfoAfterPushPull(ctx, clientInfo, docInfo1)) @@ -957,7 +960,7 @@ func RunCreateChangeInfosTest(t *testing.T, db database.Database, projectID type doc := document.New(key.Key(t.Name())) doc.SetActor(actorID) - // 02. update document only presence + // 02. Update document only presence assert.NoError(t, doc.Update(func(root *json.Object, p *presence.Presence) error { p.Set("key", "val") return nil @@ -968,7 +971,7 @@ func RunCreateChangeInfosTest(t *testing.T, db database.Database, projectID type docInfo2, _ := db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), docKey, true) assert.Equal(t, updatedAt, docInfo2.UpdatedAt) - // 03. update document presence and operation + // 03. Update document presence and operation assert.NoError(t, doc.Update(func(root *json.Object, p *presence.Presence) error { p.Set("key", "val") root.SetNewArray("array")