Skip to content
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
7 changes: 3 additions & 4 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,9 @@ func (suite *GorseClientTestSuite) TestNeighbors() {
func (suite *GorseClientTestSuite) TestUsers() {
ctx := context.TODO()
user := client.User{
UserId: "100",
Labels: []string{"a", "b", "c"},
Subscribe: []string{"d", "e"},
Comment: "comment",
UserId: "100",
Labels: []string{"a", "b", "c"},
Comment: "comment",
}
userPatch := client.UserPatch{
Comment: &user.Comment,
Expand Down
7 changes: 3 additions & 4 deletions dataset/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,9 @@ func (d *Dataset) GetItemColumnValuesIDF() []float32 {

func (d *Dataset) AddUser(user data.User) {
d.users = append(d.users, data.User{
UserId: user.UserId,
Labels: d.userLabels.processLabels(user.Labels, ""),
Subscribe: user.Subscribe,
Comment: user.Comment,
UserId: user.UserId,
Labels: d.userLabels.processLabels(user.Labels, ""),
Comment: user.Comment,
})
d.userDict.AddNoCount(user.UserId)
if len(d.userFeedback) < len(d.users) {
Expand Down
24 changes: 12 additions & 12 deletions master/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ func (s *MasterTestSuite) TestUserToUser() {
s.Config.Master.NumJobs = 4
// collect similar
users := []data.User{
{UserId: "0", Labels: []string{"a", "b", "c", "d"}, Subscribe: nil, Comment: ""},
{UserId: "1", Labels: []string{}, Subscribe: nil, Comment: ""},
{UserId: "2", Labels: []string{"b", "c", "d"}, Subscribe: nil, Comment: ""},
{UserId: "3", Labels: []string{}, Subscribe: nil, Comment: ""},
{UserId: "4", Labels: []string{"b", "c"}, Subscribe: nil, Comment: ""},
{UserId: "5", Labels: []string{}, Subscribe: nil, Comment: ""},
{UserId: "6", Labels: []string{"c"}, Subscribe: nil, Comment: ""},
{UserId: "7", Labels: []string{}, Subscribe: nil, Comment: ""},
{UserId: "8", Labels: []string{"a", "b", "c", "d", "e"}, Subscribe: nil, Comment: ""},
{UserId: "9", Labels: []string{}, Subscribe: nil, Comment: ""},
{UserId: "0", Labels: []string{"a", "b", "c", "d"}, Comment: ""},
{UserId: "1", Labels: []string{}, Comment: ""},
{UserId: "2", Labels: []string{"b", "c", "d"}, Comment: ""},
{UserId: "3", Labels: []string{}, Comment: ""},
{UserId: "4", Labels: []string{"b", "c"}, Comment: ""},
{UserId: "5", Labels: []string{}, Comment: ""},
{UserId: "6", Labels: []string{"c"}, Comment: ""},
{UserId: "7", Labels: []string{}, Comment: ""},
{UserId: "8", Labels: []string{"a", "b", "c", "d", "e"}, Comment: ""},
{UserId: "9", Labels: []string{}, Comment: ""},
}
feedbacks := make([]data.Feedback, 0)
for i := 0; i < 10; i++ {
Expand Down Expand Up @@ -511,8 +511,8 @@ func (s *MasterTestSuite) TestGarbageCollection() {

// insert users
err = s.DataClient.BatchInsertUsers(ctx, []data.User{
{UserId: "1", Labels: []string{"a", "b", "c", "d"}, Subscribe: nil, Comment: ""},
{UserId: "2", Labels: []string{}, Subscribe: nil, Comment: ""},
{UserId: "1", Labels: []string{"a", "b", "c", "d"}, Comment: ""},
{UserId: "2", Labels: []string{}, Comment: ""},
})
s.NoError(err)

Expand Down
12 changes: 5 additions & 7 deletions storage/data/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,15 @@ type ItemPatch struct {

// User stores meta data about user.
type User struct {
UserId string `gorm:"primaryKey" mapstructure:"user_id"`
Labels any `gorm:"serializer:json" mapstructure:"labels"`
Subscribe []string `gorm:"serializer:json" mapstructure:"subscribe"`
Comment string `mapstructure:"comment"`
UserId string `gorm:"primaryKey" mapstructure:"user_id"`
Labels any `gorm:"serializer:json" mapstructure:"labels"`
Comment string `mapstructure:"comment"`
}

// UserPatch is the modification on a user.
type UserPatch struct {
Labels any
Subscribe []string
Comment *string
Labels any
Comment *string
}

// FeedbackKey identifies feedback.
Expand Down
8 changes: 2 additions & 6 deletions storage/data/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,12 @@ func (suite *baseTestSuite) TestUsers() {
suite.NoError(err)
err = suite.Database.ModifyUser(ctx, "1", UserPatch{Labels: []string{"a", "b", "c"}})
suite.NoError(err)
err = suite.Database.ModifyUser(ctx, "1", UserPatch{Subscribe: []string{"d", "e", "f"}})
suite.NoError(err)
err = suite.Database.Optimize()
suite.NoError(err)
user, err = suite.Database.GetUser(ctx, "1")
suite.NoError(err)
suite.Equal("modify", user.Comment)
suite.Equal([]any{"a", "b", "c"}, user.Labels)
suite.Equal([]string{"d", "e", "f"}, user.Subscribe)

// test insert empty
err = suite.Database.BatchInsertUsers(ctx, nil)
Expand All @@ -251,7 +248,7 @@ func (suite *baseTestSuite) TestUsers() {
func (suite *baseTestSuite) TestFeedback() {
ctx := context.Background()
// users that already exists
err := suite.Database.BatchInsertUsers(ctx, []User{{"0", []string{"a"}, []string{"x"}, "comment"}})
err := suite.Database.BatchInsertUsers(ctx, []User{{"0", []string{"a"}, "comment"}})
suite.NoError(err)
// items that already exists
err = suite.Database.BatchInsertItems(ctx, []Item{{ItemId: "0", Labels: []string{"b"}, Timestamp: time.Date(1996, 4, 8, 10, 0, 0, 0, time.UTC)}})
Expand Down Expand Up @@ -347,14 +344,13 @@ func (suite *baseTestSuite) TestFeedback() {
suite.Equal(strconv.Itoa(i), user.UserId)
if user.UserId != "0" {
suite.Empty(user.Labels)
suite.Empty(user.Subscribe)
suite.Empty(user.Comment)
}
}
// check users that already exists
user, err := suite.Database.GetUser(ctx, "0")
suite.NoError(err)
suite.Equal(User{"0", []any{"a"}, []string{"x"}, "comment"}, user)
suite.Equal(User{"0", []any{"a"}, "comment"}, user)
// check items that already exists
item, err := suite.Database.GetItem(ctx, "0")
suite.NoError(err)
Expand Down
3 changes: 0 additions & 3 deletions storage/data/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,6 @@ func (db *MongoDB) ModifyUser(ctx context.Context, userId string, patch UserPatc
if patch.Comment != nil {
update["comment"] = patch.Comment
}
if patch.Subscribe != nil {
update["subscribe"] = patch.Subscribe
}
// execute
c := db.client.Database(db.dbName).Collection(db.UsersTable())
_, err := c.UpdateOne(ctx, bson.M{"userid": bson.M{"$eq": userId}}, bson.M{"$set": update})
Expand Down
66 changes: 28 additions & 38 deletions storage/data/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,9 @@ func (p *ProxyServer) BatchInsertUsers(ctx context.Context, in *protocol.BatchIn
return nil, err
}
users[i] = User{
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
Subscribe: user.Subscribe,
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
}
}
err := p.database.BatchInsertUsers(ctx, users)
Expand All @@ -236,10 +235,9 @@ func (p *ProxyServer) GetUser(ctx context.Context, in *protocol.GetUserRequest)
}
return &protocol.GetUserResponse{
User: &protocol.User{
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
Subscribe: user.Subscribe,
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
},
}, nil
}
Expand All @@ -253,9 +251,8 @@ func (p *ProxyServer) ModifyUser(ctx context.Context, in *protocol.ModifyUserReq
}
}
err := p.database.ModifyUser(ctx, in.UserId, UserPatch{
Labels: labels,
Comment: in.Patch.Comment,
Subscribe: in.Patch.Subscribe,
Labels: labels,
Comment: in.Patch.Comment,
})
return &protocol.ModifyUserResponse{}, err
}
Expand All @@ -272,10 +269,9 @@ func (p *ProxyServer) GetUsers(ctx context.Context, in *protocol.GetUsersRequest
return nil, err
}
pbUsers[i] = &protocol.User{
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
Subscribe: user.Subscribe,
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
}
}
return &protocol.GetUsersResponse{Cursor: cursor, Users: pbUsers}, nil
Expand Down Expand Up @@ -394,10 +390,9 @@ func (p *ProxyServer) GetUserStream(in *protocol.GetUserStreamRequest, stream gr
return err
}
pbUsers[i] = &protocol.User{
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
Subscribe: user.Subscribe,
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
}
}
err := stream.Send(&protocol.GetUserStreamResponse{Users: pbUsers})
Expand Down Expand Up @@ -696,10 +691,9 @@ func (p ProxyClient) BatchInsertUsers(ctx context.Context, users []User) error {
return err
}
pbUsers[i] = &protocol.User{
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
Subscribe: user.Subscribe,
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
}
}
_, err := p.DataStoreClient.BatchInsertUsers(ctx, &protocol.BatchInsertUsersRequest{Users: pbUsers})
Expand All @@ -724,10 +718,9 @@ func (p ProxyClient) GetUser(ctx context.Context, userId string) (User, error) {
return User{}, err
}
return User{
UserId: resp.User.UserId,
Labels: labels,
Comment: resp.User.Comment,
Subscribe: resp.User.Subscribe,
UserId: resp.User.UserId,
Labels: labels,
Comment: resp.User.Comment,
}, nil
}

Expand All @@ -743,9 +736,8 @@ func (p ProxyClient) ModifyUser(ctx context.Context, userId string, patch UserPa
_, err := p.DataStoreClient.ModifyUser(ctx, &protocol.ModifyUserRequest{
UserId: userId,
Patch: &protocol.UserPatch{
Labels: labels,
Comment: patch.Comment,
Subscribe: patch.Subscribe,
Labels: labels,
Comment: patch.Comment,
},
})
return err
Expand All @@ -764,10 +756,9 @@ func (p ProxyClient) GetUsers(ctx context.Context, cursor string, n int) (string
return "", nil, err
}
users[i] = User{
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
Subscribe: user.Subscribe,
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
}
}
return resp.Cursor, users, nil
Expand Down Expand Up @@ -933,10 +924,9 @@ func (p ProxyClient) GetUserStream(ctx context.Context, batchSize int) (chan []U
return
}
users[i] = User{
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
Subscribe: user.Subscribe,
UserId: user.UserId,
Labels: labels,
Comment: user.Comment,
}
}
usersChan <- users
Expand Down
Loading