]> source.dussan.org Git - gitea.git/commitdiff
Don't join repository when loading action table data (#32127)
authorLunny Xiao <xiaolunwen@gmail.com>
Thu, 26 Sep 2024 04:50:30 +0000 (12:50 +0800)
committerGitHub <noreply@github.com>
Thu, 26 Sep 2024 04:50:30 +0000 (04:50 +0000)
models/activities/action.go
models/activities/action_test.go

index 532667d49579890f91f63e63b1b2af47c9a53322..9b4ffd7725c4e000cd795af51607ba659c3d6d15 100644 (file)
@@ -452,13 +452,10 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
 
        actions := make([]*Action, 0, opts.PageSize)
        var count int64
+       opts.SetDefaultValues()
 
        if opts.Page < 10 { // TODO: why it's 10 but other values? It's an experience value.
-               sess := db.GetEngine(ctx).Where(cond).
-                       Select("`action`.*"). // this line will avoid select other joined table's columns
-                       Join("INNER", "repository", "`repository`.id = `action`.repo_id")
-
-               opts.SetDefaultValues()
+               sess := db.GetEngine(ctx).Where(cond)
                sess = db.SetSessionPagination(sess, &opts)
 
                count, err = sess.Desc("`action`.created_unix").FindAndCount(&actions)
@@ -467,11 +464,7 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
                }
        } else {
                // First, only query which IDs are necessary, and only then query all actions to speed up the overall query
-               sess := db.GetEngine(ctx).Where(cond).
-                       Select("`action`.id").
-                       Join("INNER", "repository", "`repository`.id = `action`.repo_id")
-
-               opts.SetDefaultValues()
+               sess := db.GetEngine(ctx).Where(cond).Select("`action`.id")
                sess = db.SetSessionPagination(sess, &opts)
 
                actionIDs := make([]int64, 0, opts.PageSize)
@@ -481,8 +474,7 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
 
                count, err = db.GetEngine(ctx).Where(cond).
                        Table("action").
-                       Cols("`action`.id").
-                       Join("INNER", "repository", "`repository`.id = `action`.repo_id").Count()
+                       Cols("`action`.id").Count()
                if err != nil {
                        return nil, 0, fmt.Errorf("Count: %w", err)
                }
index 36a38c786397122535b9f10c9c74a05f3f9f122b..e5dee33ae02242864e00ed9c595e045cdaf62fe1 100644 (file)
@@ -228,6 +228,8 @@ func TestNotifyWatchers(t *testing.T) {
 }
 
 func TestGetFeedsCorrupted(t *testing.T) {
+       // Now we will not check for corrupted data in the feeds
+       // users should run doctor to fix their data
        assert.NoError(t, unittest.PrepareTestDatabase())
        user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
        unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
@@ -241,8 +243,8 @@ func TestGetFeedsCorrupted(t *testing.T) {
                IncludePrivate: true,
        })
        assert.NoError(t, err)
-       assert.Len(t, actions, 0)
-       assert.Equal(t, int64(0), count)
+       assert.Len(t, actions, 1)
+       assert.Equal(t, int64(1), count)
 }
 
 func TestConsistencyUpdateAction(t *testing.T) {