@@ -98,44 +98,48 @@ var ErrIssueAlreadyChanged = util.NewInvalidArgumentErrorf("the issue is already
98
98
99
99
// Issue represents an issue or pull request of repository.
100
100
type Issue struct {
101
- ID int64 `xorm:"pk autoincr"`
102
- RepoID int64 `xorm:"INDEX UNIQUE(repo_index)"`
103
- Repo * repo_model.Repository `xorm:"-"`
104
- Index int64 `xorm:"UNIQUE(repo_index)"` // Index in one repository.
105
- PosterID int64 `xorm:"INDEX"`
106
- Poster * user_model.User `xorm:"-"`
107
- OriginalAuthor string
108
- OriginalAuthorID int64 `xorm:"index"`
109
- Title string `xorm:"name"`
110
- Content string `xorm:"LONGTEXT"`
111
- RenderedContent template.HTML `xorm:"-"`
112
- ContentVersion int `xorm:"NOT NULL DEFAULT 0"`
113
- Labels []* Label `xorm:"-"`
114
- MilestoneID int64 `xorm:"INDEX"`
115
- Milestone * Milestone `xorm:"-"`
116
- Project * project_model.Project `xorm:"-"`
117
- Priority int
118
- AssigneeID int64 `xorm:"-"`
119
- Assignee * user_model.User `xorm:"-"`
120
- IsClosed bool `xorm:"INDEX"`
121
- IsRead bool `xorm:"-"`
122
- IsPull bool `xorm:"INDEX"` // Indicates whether is a pull request or not.
123
- PullRequest * PullRequest `xorm:"-"`
124
- NumComments int
125
- Ref string
126
- PinOrder int `xorm:"DEFAULT 0"`
101
+ ID int64 `xorm:"pk autoincr"`
102
+ RepoID int64 `xorm:"INDEX UNIQUE(repo_index)"`
103
+ Repo * repo_model.Repository `xorm:"-"`
104
+ Index int64 `xorm:"UNIQUE(repo_index)"` // Index in one repository.
105
+ PosterID int64 `xorm:"INDEX"`
106
+ Poster * user_model.User `xorm:"-"`
107
+ OriginalAuthor string
108
+ OriginalAuthorID int64 `xorm:"index"`
109
+ Title string `xorm:"name"`
110
+ Content string `xorm:"LONGTEXT"`
111
+ RenderedContent template.HTML `xorm:"-"`
112
+ ContentVersion int `xorm:"NOT NULL DEFAULT 0"`
113
+ Labels []* Label `xorm:"-"`
114
+ isLabelsLoaded bool `xorm:"-"`
115
+ MilestoneID int64 `xorm:"INDEX"`
116
+ Milestone * Milestone `xorm:"-"`
117
+ isMilestoneLoaded bool `xorm:"-"`
118
+ Project * project_model.Project `xorm:"-"`
119
+ Priority int
120
+ AssigneeID int64 `xorm:"-"`
121
+ Assignee * user_model.User `xorm:"-"`
122
+ isAssigneeLoaded bool `xorm:"-"`
123
+ IsClosed bool `xorm:"INDEX"`
124
+ IsRead bool `xorm:"-"`
125
+ IsPull bool `xorm:"INDEX"` // Indicates whether is a pull request or not.
126
+ PullRequest * PullRequest `xorm:"-"`
127
+ NumComments int
128
+ Ref string
129
+ PinOrder int `xorm:"DEFAULT 0"`
127
130
128
131
DeadlineUnix timeutil.TimeStamp `xorm:"INDEX"`
129
132
130
133
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
131
134
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
132
135
ClosedUnix timeutil.TimeStamp `xorm:"INDEX"`
133
136
134
- Attachments []* repo_model.Attachment `xorm:"-"`
135
- Comments CommentList `xorm:"-"`
136
- Reactions ReactionList `xorm:"-"`
137
- TotalTrackedTime int64 `xorm:"-"`
138
- Assignees []* user_model.User `xorm:"-"`
137
+ Attachments []* repo_model.Attachment `xorm:"-"`
138
+ isAttachmentsLoaded bool `xorm:"-"`
139
+ Comments CommentList `xorm:"-"`
140
+ Reactions ReactionList `xorm:"-"`
141
+ TotalTrackedTime int64 `xorm:"-"`
142
+ Assignees []* user_model.User `xorm:"-"`
139
143
140
144
// IsLocked limits commenting abilities to users on an issue
141
145
// with write access
@@ -187,6 +191,19 @@ func (issue *Issue) LoadRepo(ctx context.Context) (err error) {
187
191
return nil
188
192
}
189
193
194
+ func (issue * Issue ) LoadAttachments (ctx context.Context ) (err error ) {
195
+ if issue .isAttachmentsLoaded || issue .Attachments != nil {
196
+ return nil
197
+ }
198
+
199
+ issue .Attachments , err = repo_model .GetAttachmentsByIssueID (ctx , issue .ID )
200
+ if err != nil {
201
+ return fmt .Errorf ("getAttachmentsByIssueID [%d]: %w" , issue .ID , err )
202
+ }
203
+ issue .isAttachmentsLoaded = true
204
+ return nil
205
+ }
206
+
190
207
// IsTimetrackerEnabled returns true if the repo enables timetracking
191
208
func (issue * Issue ) IsTimetrackerEnabled (ctx context.Context ) bool {
192
209
if err := issue .LoadRepo (ctx ); err != nil {
@@ -287,11 +304,12 @@ func (issue *Issue) loadReactions(ctx context.Context) (err error) {
287
304
288
305
// LoadMilestone load milestone of this issue.
289
306
func (issue * Issue ) LoadMilestone (ctx context.Context ) (err error ) {
290
- if (issue .Milestone == nil || issue .Milestone .ID != issue .MilestoneID ) && issue .MilestoneID > 0 {
307
+ if ! issue . isMilestoneLoaded && (issue .Milestone == nil || issue .Milestone .ID != issue .MilestoneID ) && issue .MilestoneID > 0 {
291
308
issue .Milestone , err = GetMilestoneByRepoID (ctx , issue .RepoID , issue .MilestoneID )
292
309
if err != nil && ! IsErrMilestoneNotExist (err ) {
293
310
return fmt .Errorf ("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %w" , issue .RepoID , issue .MilestoneID , err )
294
311
}
312
+ issue .isMilestoneLoaded = true
295
313
}
296
314
return nil
297
315
}
@@ -327,11 +345,8 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) {
327
345
return err
328
346
}
329
347
330
- if issue .Attachments == nil {
331
- issue .Attachments , err = repo_model .GetAttachmentsByIssueID (ctx , issue .ID )
332
- if err != nil {
333
- return fmt .Errorf ("getAttachmentsByIssueID [%d]: %w" , issue .ID , err )
334
- }
348
+ if err = issue .LoadAttachments (ctx ); err != nil {
349
+ return err
335
350
}
336
351
337
352
if err = issue .loadComments (ctx ); err != nil {
@@ -350,6 +365,13 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) {
350
365
return issue .loadReactions (ctx )
351
366
}
352
367
368
+ func (issue * Issue ) ResetAttributesLoaded () {
369
+ issue .isLabelsLoaded = false
370
+ issue .isMilestoneLoaded = false
371
+ issue .isAttachmentsLoaded = false
372
+ issue .isAssigneeLoaded = false
373
+ }
374
+
353
375
// GetIsRead load the `IsRead` field of the issue
354
376
func (issue * Issue ) GetIsRead (ctx context.Context , userID int64 ) error {
355
377
issueUser := & IssueUser {IssueID : issue .ID , UID : userID }
0 commit comments