Skip to content

Commit 3f9e360

Browse files
authored
Don't join repository when loading action table data (#32127)
1 parent 3269b04 commit 3f9e360

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

models/activities/action.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,10 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
452452

453453
actions := make([]*Action, 0, opts.PageSize)
454454
var count int64
455+
opts.SetDefaultValues()
455456

456457
if opts.Page < 10 { // TODO: why it's 10 but other values? It's an experience value.
457-
sess := db.GetEngine(ctx).Where(cond).
458-
Select("`action`.*"). // this line will avoid select other joined table's columns
459-
Join("INNER", "repository", "`repository`.id = `action`.repo_id")
460-
461-
opts.SetDefaultValues()
458+
sess := db.GetEngine(ctx).Where(cond)
462459
sess = db.SetSessionPagination(sess, &opts)
463460

464461
count, err = sess.Desc("`action`.created_unix").FindAndCount(&actions)
@@ -467,11 +464,7 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
467464
}
468465
} else {
469466
// First, only query which IDs are necessary, and only then query all actions to speed up the overall query
470-
sess := db.GetEngine(ctx).Where(cond).
471-
Select("`action`.id").
472-
Join("INNER", "repository", "`repository`.id = `action`.repo_id")
473-
474-
opts.SetDefaultValues()
467+
sess := db.GetEngine(ctx).Where(cond).Select("`action`.id")
475468
sess = db.SetSessionPagination(sess, &opts)
476469

477470
actionIDs := make([]int64, 0, opts.PageSize)
@@ -481,8 +474,7 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
481474

482475
count, err = db.GetEngine(ctx).Where(cond).
483476
Table("action").
484-
Cols("`action`.id").
485-
Join("INNER", "repository", "`repository`.id = `action`.repo_id").Count()
477+
Cols("`action`.id").Count()
486478
if err != nil {
487479
return nil, 0, fmt.Errorf("Count: %w", err)
488480
}

models/activities/action_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ func TestNotifyWatchers(t *testing.T) {
228228
}
229229

230230
func TestGetFeedsCorrupted(t *testing.T) {
231+
// Now we will not check for corrupted data in the feeds
232+
// users should run doctor to fix their data
231233
assert.NoError(t, unittest.PrepareTestDatabase())
232234
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
233235
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
@@ -241,8 +243,8 @@ func TestGetFeedsCorrupted(t *testing.T) {
241243
IncludePrivate: true,
242244
})
243245
assert.NoError(t, err)
244-
assert.Len(t, actions, 0)
245-
assert.Equal(t, int64(0), count)
246+
assert.Len(t, actions, 1)
247+
assert.Equal(t, int64(1), count)
246248
}
247249

248250
func TestConsistencyUpdateAction(t *testing.T) {

0 commit comments

Comments
 (0)