Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbebe4f0

Browse files
chore: sort inserted users on dbmem (#15483)
1 parent97b3bbf commitbebe4f0

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

‎coderd/database/dbmem/dbmem.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7714,21 +7714,6 @@ func (q *FakeQuerier) InsertUser(_ context.Context, arg database.InsertUserParam
77147714
return database.User{},err
77157715
}
77167716

7717-
// There is a common bug when using dbmem that 2 inserted users have the
7718-
// same created_at time. This causes user order to not be deterministic,
7719-
// which breaks some unit tests.
7720-
// To fix this, we make sure that the created_at time is always greater
7721-
// than the last user's created_at time.
7722-
allUsers,_:=q.GetUsers(context.Background(), database.GetUsersParams{})
7723-
iflen(allUsers)>0 {
7724-
lastUser:=allUsers[len(allUsers)-1]
7725-
ifarg.CreatedAt.Before(lastUser.CreatedAt)||
7726-
arg.CreatedAt.Equal(lastUser.CreatedAt) {
7727-
// 1 ms is a good enough buffer.
7728-
arg.CreatedAt=lastUser.CreatedAt.Add(time.Millisecond)
7729-
}
7730-
}
7731-
77327717
q.mutex.Lock()
77337718
deferq.mutex.Unlock()
77347719

@@ -7756,6 +7741,9 @@ func (q *FakeQuerier) InsertUser(_ context.Context, arg database.InsertUserParam
77567741
LoginType:arg.LoginType,
77577742
}
77587743
q.users=append(q.users,user)
7744+
sort.Slice(q.users,func(i,jint)bool {
7745+
returnq.users[i].CreatedAt.Before(q.users[j].CreatedAt)
7746+
})
77597747
returnuser,nil
77607748
}
77617749

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp