-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move issue pin to an standalone table for querying performance #33452
base: main
Are you sure you want to change the base?
Conversation
models/issues/issue.go
Outdated
@@ -341,6 +360,11 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) { | |||
return issue.loadReactions(ctx) | |||
} | |||
|
|||
// IsPinned returns if a Issue is pinned | |||
func (issue *Issue) IsPinned() bool { | |||
return issue.PinOrder != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to add an panic check: if pinOrderLoaded=false, panic to tell developers that there is a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you'd like to use the convention that PinOrder > 0
means "pinned", you can use PinOrder=-1
means loaded, then no need to introduce another fragile pinOrderLoaded field. -1
also means non-existing, so it matches the meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Pin pins a Issue | ||
func PinIssue(ctx context.Context, issue *Issue, user *user_model.User) error { | ||
return db.WithTx(ctx, func(ctx context.Context) error { | ||
pinnedIssuesNum, err := getPinnedIssuesNum(ctx, issue.RepoID, issue.IsPull) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changed logic is wrong.
It can't use count
(from getPinnedIssuesNum) here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why it can't use count
. getPinnedIssuesNum
returned the records in the database which means how many issues have been pinned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Order: 1, 2, 3
- 2 is deleted
- count() == 2, then pinnedIssuesNum + 1 == 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if _, err = db.GetEngine(ctx).Insert(&IssuePin{ | ||
RepoID: issue.RepoID, | ||
IssueID: issue.ID, | ||
IsPull: issue.IsPull, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see there is no default value for IsPull bool `xorm:"NOT NULL"`
Then if IsPull==false
, will XORM generate the column for the SQL?
Noticed a SQL in gitea.com has a bigger load. It seems both
is_pull
andpin_order
are not indexed columns in the database.I came across a comment #24406 (comment) from @delvh , which presents a more reasonable approach. Based on this, this PR will migrate all issue and pull request pin data from the
issue
table to theissue_pin
table. This change benefits larger Gitea instances by improving scalability and performance.