Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set updated_at with created_at when creating Document #977

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/backend/database/memory/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion server/backend/database/mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions server/backend/database/testcases/testcases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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")
Expand Down
Loading