Skip to content

Commit 077040a

Browse files
authored
Merge branch 'main' into configurable-internal-hook-timeout
2 parents bd80d6a + 279473f commit 077040a

File tree

31 files changed

+425
-240
lines changed

31 files changed

+425
-240
lines changed

models/activities/action.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ func (a *Action) TableIndices() []*schemas.Index {
172172
cuIndex := schemas.NewIndex("c_u", schemas.IndexType)
173173
cuIndex.AddColumn("user_id", "is_deleted")
174174

175-
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex, cuIndex}
175+
actUserUserIndex := schemas.NewIndex("au_c_u", schemas.IndexType)
176+
actUserUserIndex.AddColumn("act_user_id", "created_unix", "user_id")
177+
178+
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex, cuIndex, actUserUserIndex}
176179

177180
return indices
178181
}
@@ -442,6 +445,7 @@ type GetFeedsOptions struct {
442445
OnlyPerformedBy bool // only actions performed by requested user
443446
IncludeDeleted bool // include deleted actions
444447
Date string // the day we want activity for: YYYY-MM-DD
448+
DontCount bool // do counting in GetFeeds
445449
}
446450

447451
// ActivityReadable return whether doer can read activities of user

models/activities/action_list.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
243243
sess := db.GetEngine(ctx).Where(cond)
244244
sess = db.SetSessionPagination(sess, &opts)
245245

246-
count, err = sess.Desc("`action`.created_unix").FindAndCount(&actions)
246+
if opts.DontCount {
247+
err = sess.Desc("`action`.created_unix").Find(&actions)
248+
} else {
249+
count, err = sess.Desc("`action`.created_unix").FindAndCount(&actions)
250+
}
247251
if err != nil {
248252
return nil, 0, fmt.Errorf("FindAndCount: %w", err)
249253
}
@@ -257,11 +261,13 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
257261
return nil, 0, fmt.Errorf("Find(actionsIDs): %w", err)
258262
}
259263

260-
count, err = db.GetEngine(ctx).Where(cond).
261-
Table("action").
262-
Cols("`action`.id").Count()
263-
if err != nil {
264-
return nil, 0, fmt.Errorf("Count: %w", err)
264+
if !opts.DontCount {
265+
count, err = db.GetEngine(ctx).Where(cond).
266+
Table("action").
267+
Cols("`action`.id").Count()
268+
if err != nil {
269+
return nil, 0, fmt.Errorf("Count: %w", err)
270+
}
265271
}
266272

267273
if err := db.GetEngine(ctx).In("`action`.id", actionIDs).Desc("`action`.created_unix").Find(&actions); err != nil {
@@ -275,3 +281,9 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
275281

276282
return actions, count, nil
277283
}
284+
285+
func CountUserFeeds(ctx context.Context, userID int64) (int64, error) {
286+
return db.GetEngine(ctx).Where("user_id = ?", userID).
287+
And("is_deleted = ?", false).
288+
Count(&Action{})
289+
}

models/db/search.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@ const (
2929
// NoConditionID means a condition to filter the records which don't match any id.
3030
// eg: "milestone_id=-1" means "find the items without any milestone.
3131
const NoConditionID int64 = -1
32-
33-
// NonExistingID means a condition to match no result (eg: a non-existing user)
34-
// It doesn't use -1 or -2 because they are used as builtin users.
35-
const NonExistingID int64 = -1000000

models/issues/issue_search.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ type IssuesOptions struct { //nolint
2727
RepoIDs []int64 // overwrites RepoCond if the length is not 0
2828
AllPublic bool // include also all public repositories
2929
RepoCond builder.Cond
30-
AssigneeID optional.Option[int64]
31-
PosterID optional.Option[int64]
30+
AssigneeID string // "(none)" or "(any)" or a user ID
31+
PosterID string // "(none)" or "(any)" or a user ID
3232
MentionedID int64
3333
ReviewRequestedID int64
3434
ReviewedID int64
@@ -356,26 +356,25 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, owner *user_mod
356356
return cond
357357
}
358358

359-
func applyAssigneeCondition(sess *xorm.Session, assigneeID optional.Option[int64]) {
359+
func applyAssigneeCondition(sess *xorm.Session, assigneeID string) {
360360
// old logic: 0 is also treated as "not filtering assignee", because the "assignee" was read as FormInt64
361-
if !assigneeID.Has() || assigneeID.Value() == 0 {
362-
return
363-
}
364-
if assigneeID.Value() == db.NoConditionID {
361+
if assigneeID == "(none)" {
365362
sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_assignees)")
366-
} else {
363+
} else if assigneeID == "(any)" {
364+
sess.Where("issue.id IN (SELECT issue_id FROM issue_assignees)")
365+
} else if assigneeIDInt64, _ := strconv.ParseInt(assigneeID, 10, 64); assigneeIDInt64 > 0 {
367366
sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
368-
And("issue_assignees.assignee_id = ?", assigneeID.Value())
367+
And("issue_assignees.assignee_id = ?", assigneeIDInt64)
369368
}
370369
}
371370

372-
func applyPosterCondition(sess *xorm.Session, posterID optional.Option[int64]) {
373-
if !posterID.Has() {
374-
return
375-
}
376-
// poster doesn't need to support db.NoConditionID(-1), so just use the value as-is
377-
if posterID.Has() {
378-
sess.And("issue.poster_id=?", posterID.Value())
371+
func applyPosterCondition(sess *xorm.Session, posterID string) {
372+
// Actually every issue has a poster.
373+
// The "(none)" is for internal usage only: when doer tries to search non-existing user as poster, use "(none)" to return empty result.
374+
if posterID == "(none)" {
375+
sess.And("issue.poster_id=0")
376+
} else if posterIDInt64, _ := strconv.ParseInt(posterID, 10, 64); posterIDInt64 > 0 {
377+
sess.And("issue.poster_id=?", posterIDInt64)
379378
}
380379
}
381380

models/issues/issue_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
repo_model "code.gitea.io/gitea/models/repo"
1616
"code.gitea.io/gitea/models/unittest"
1717
user_model "code.gitea.io/gitea/models/user"
18-
"code.gitea.io/gitea/modules/optional"
1918
"code.gitea.io/gitea/modules/setting"
2019

2120
"github.com/stretchr/testify/assert"
@@ -155,7 +154,7 @@ func TestIssues(t *testing.T) {
155154
}{
156155
{
157156
issues_model.IssuesOptions{
158-
AssigneeID: optional.Some(int64(1)),
157+
AssigneeID: "1",
159158
SortType: "oldest",
160159
},
161160
[]int64{1, 6},

models/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ func prepareMigrationTasks() []*migration {
377377
newMigration(314, "Update OwnerID as zero for repository level action tables", v1_24.UpdateOwnerIDOfRepoLevelActionsTables),
378378
newMigration(315, "Add Ephemeral to ActionRunner", v1_24.AddEphemeralToActionRunner),
379379
newMigration(316, "Add description for secrets and variables", v1_24.AddDescriptionForSecretsAndVariables),
380+
newMigration(317, "Add new index for action for heatmap", v1_24.AddNewIndexForUserDashboard),
380381
}
381382
return preparedMigrations
382383
}

models/migrations/v1_24/v317.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_24 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/timeutil"
8+
9+
"xorm.io/xorm"
10+
"xorm.io/xorm/schemas"
11+
)
12+
13+
type improveActionTableIndicesAction struct {
14+
ID int64 `xorm:"pk autoincr"`
15+
UserID int64 `xorm:"INDEX"` // Receiver user id.
16+
OpType int
17+
ActUserID int64 // Action user id.
18+
RepoID int64
19+
CommentID int64 `xorm:"INDEX"`
20+
IsDeleted bool `xorm:"NOT NULL DEFAULT false"`
21+
RefName string
22+
IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
23+
Content string `xorm:"TEXT"`
24+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
25+
}
26+
27+
// TableName sets the name of this table
28+
func (*improveActionTableIndicesAction) TableName() string {
29+
return "action"
30+
}
31+
32+
// TableIndices implements xorm's TableIndices interface
33+
func (a *improveActionTableIndicesAction) TableIndices() []*schemas.Index {
34+
repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
35+
repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
36+
37+
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
38+
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
39+
40+
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
41+
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
42+
43+
cuIndex := schemas.NewIndex("c_u", schemas.IndexType)
44+
cuIndex.AddColumn("user_id", "is_deleted")
45+
46+
actUserUserIndex := schemas.NewIndex("au_c_u", schemas.IndexType)
47+
actUserUserIndex.AddColumn("act_user_id", "created_unix", "user_id")
48+
49+
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex, cuIndex, actUserUserIndex}
50+
51+
return indices
52+
}
53+
54+
func AddNewIndexForUserDashboard(x *xorm.Engine) error {
55+
return x.Sync(new(improveActionTableIndicesAction))
56+
}

modules/indexer/issues/bleve/bleve.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ package bleve
55

66
import (
77
"context"
8+
"strconv"
89

910
"code.gitea.io/gitea/modules/indexer"
1011
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
1112
inner_bleve "code.gitea.io/gitea/modules/indexer/internal/bleve"
1213
"code.gitea.io/gitea/modules/indexer/issues/internal"
14+
"code.gitea.io/gitea/modules/optional"
1315
"code.gitea.io/gitea/modules/util"
1416

1517
"github.com/blevesearch/bleve/v2"
@@ -246,12 +248,20 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
246248
queries = append(queries, inner_bleve.NumericEqualityQuery(options.ProjectColumnID.Value(), "project_board_id"))
247249
}
248250

249-
if options.PosterID.Has() {
250-
queries = append(queries, inner_bleve.NumericEqualityQuery(options.PosterID.Value(), "poster_id"))
251+
if options.PosterID != "" {
252+
// "(none)" becomes 0, it means no poster
253+
posterIDInt64, _ := strconv.ParseInt(options.PosterID, 10, 64)
254+
queries = append(queries, inner_bleve.NumericEqualityQuery(posterIDInt64, "poster_id"))
251255
}
252256

253-
if options.AssigneeID.Has() {
254-
queries = append(queries, inner_bleve.NumericEqualityQuery(options.AssigneeID.Value(), "assignee_id"))
257+
if options.AssigneeID != "" {
258+
if options.AssigneeID == "(any)" {
259+
queries = append(queries, inner_bleve.NumericRangeInclusiveQuery(optional.Some[int64](1), optional.None[int64](), "assignee_id"))
260+
} else {
261+
// "(none)" becomes 0, it means no assignee
262+
assigneeIDInt64, _ := strconv.ParseInt(options.AssigneeID, 10, 64)
263+
queries = append(queries, inner_bleve.NumericEqualityQuery(assigneeIDInt64, "assignee_id"))
264+
}
255265
}
256266

257267
if options.MentionID.Has() {

modules/indexer/issues/db/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
5454
RepoIDs: options.RepoIDs,
5555
AllPublic: options.AllPublic,
5656
RepoCond: nil,
57-
AssigneeID: optional.Some(convertID(options.AssigneeID)),
57+
AssigneeID: options.AssigneeID,
5858
PosterID: options.PosterID,
5959
MentionedID: convertID(options.MentionID),
6060
ReviewRequestedID: convertID(options.ReviewRequestedID),

modules/indexer/issues/dboptions.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp
4545
searchOpt.ProjectID = optional.Some[int64](0) // Those issues with no project(projectid==0)
4646
}
4747

48-
if opts.AssigneeID.Value() == db.NoConditionID {
49-
searchOpt.AssigneeID = optional.Some[int64](0) // FIXME: this is inconsistent from other places, 0 means "no assignee"
50-
} else if opts.AssigneeID.Value() != 0 {
51-
searchOpt.AssigneeID = opts.AssigneeID
52-
}
48+
searchOpt.AssigneeID = opts.AssigneeID
5349

5450
// See the comment of issues_model.SearchOptions for the reason why we need to convert
5551
convertID := func(id int64) optional.Option[int64] {

0 commit comments

Comments
 (0)