Skip to content
Closed
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: 7 additions & 0 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, error) {

actions := make([]*Action, 0, opts.PageSize)

// De-duplicate any action that has the same created unix, as actions are stored for each user
// who can see that action. This probably (though there is no guarantee) means that they were the same
// action.
if opts.RequestedRepo != nil {
sess = sess.In("`action`.id", builder.Select("min(id) as id").From("action").GroupBy("`action`.created_unix, `action`.op_type, `action`.act_user_id"))
}

if err := sess.Desc("`action`.created_unix").Find(&actions); err != nil {
return nil, fmt.Errorf("Find: %v", err)
}
Expand Down
11 changes: 11 additions & 0 deletions models/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func TestGetFeedsForRepos(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
privRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
pubRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 8}).(*repo_model.Repository)
repoWithActions := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)

// private repo & no login
actions, err := GetFeeds(db.DefaultContext, GetFeedsOptions{
Expand Down Expand Up @@ -102,6 +103,16 @@ func TestGetFeedsForRepos(t *testing.T) {
})
assert.NoError(t, err)
assert.Len(t, actions, 1)

// Check repository with four actions, all of them were created
// at the same time, but two of them are comments(one should be de-duped)
// the other one is closing a issue and the last one is also comment but by a different user.
// So in told there are 3 de-deduped actions.
actions, err = GetFeeds(db.DefaultContext, GetFeedsOptions{
RequestedRepo: repoWithActions,
})
assert.NoError(t, err)
assert.Len(t, actions, 3)
}

func TestGetFeeds2(t *testing.T) {
Expand Down
35 changes: 35 additions & 0 deletions models/fixtures/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,38 @@
repo_id: 1700 # dangling intentional
is_private: false
created_unix: 1603011541

- id: 9
user_id: 10
op_type: 10
act_user_id: 10
repo_id: 1
content: HelloWorld
is_private: false
created_unix: 1603011301 # same as 10, 11, 12

- id: 10
user_id: 9
op_type: 10
act_user_id: 10
repo_id: 1
content: HelloWorld
is_private: false
created_unix: 1603011301 # same as id 9, 11, 12

- id: 11
user_id: 9
op_type: 12 # differ op_type
act_user_id: 10
repo_id: 1
is_private: false
created_unix: 1603011301 # same as id 9, 10, 12

- id: 12
user_id: 9
op_type: 10
act_user_id: 9 # differ act_user_id
repo_id: 1
content: HelloWorld
is_private: false
created_unix: 1603011301 # same as id 9, 10, 11
2 changes: 1 addition & 1 deletion models/user_heatmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
},
{
"multiple actions performed with two grouped together",
10, 10, 3, `[{"timestamp":1603009800,"contributions":1},{"timestamp":1603010700,"contributions":2}]`,
10, 10, 4, `[{"timestamp":1603009800,"contributions":1},{"timestamp":1603010700,"contributions":3}]`,
},
}
// Prepare
Expand Down