@@ -267,7 +267,7 @@ func (n *Notification) HTMLURL() string {
267
267
// NotificationList contains a list of notifications
268
268
type NotificationList []* Notification
269
269
270
- func (nl NotificationList ) getRepoIDs () []int64 {
270
+ func (nl NotificationList ) getPendingRepoIDs () []int64 {
271
271
var ids = make (map [int64 ]struct {}, len (nl ))
272
272
for _ , notification := range nl {
273
273
if notification .Repository != nil {
@@ -286,9 +286,8 @@ func (nl NotificationList) LoadRepos() (RepositoryList, error) {
286
286
return RepositoryList {}, nil
287
287
}
288
288
289
- var repoIDs = nl .getRepoIDs ()
289
+ var repoIDs = nl .getPendingRepoIDs ()
290
290
var repos = make (map [int64 ]* Repository , len (repoIDs ))
291
- var reposList = make (RepositoryList , 0 , len (repoIDs ))
292
291
var left = len (repoIDs )
293
292
for left > 0 {
294
293
var limit = defaultMaxInSize
@@ -311,23 +310,33 @@ func (nl NotificationList) LoadRepos() (RepositoryList, error) {
311
310
}
312
311
313
312
repos [repo .ID ] = & repo
314
- reposList = append (reposList , & repo )
315
313
}
316
314
_ = rows .Close ()
317
315
318
316
left -= limit
319
317
repoIDs = repoIDs [limit :]
320
318
}
321
319
320
+ var reposList = make (RepositoryList , 0 , len (repoIDs ))
322
321
for _ , notification := range nl {
323
322
if notification .Repository == nil {
324
323
notification .Repository = repos [notification .RepoID ]
325
324
}
325
+ var found bool
326
+ for _ , r := range reposList {
327
+ if r .ID == notification .Repository .ID {
328
+ found = true
329
+ break
330
+ }
331
+ }
332
+ if ! found {
333
+ reposList = append (reposList , notification .Repository )
334
+ }
326
335
}
327
336
return reposList , nil
328
337
}
329
338
330
- func (nl NotificationList ) getIssueIDs () []int64 {
339
+ func (nl NotificationList ) getPendingIssueIDs () []int64 {
331
340
var ids = make (map [int64 ]struct {}, len (nl ))
332
341
for _ , notification := range nl {
333
342
if notification .Issue != nil {
@@ -346,7 +355,7 @@ func (nl NotificationList) LoadIssues() error {
346
355
return nil
347
356
}
348
357
349
- var issueIDs = nl .getIssueIDs ()
358
+ var issueIDs = nl .getPendingIssueIDs ()
350
359
var issues = make (map [int64 ]* Issue , len (issueIDs ))
351
360
var left = len (issueIDs )
352
361
for left > 0 {
@@ -380,15 +389,13 @@ func (nl NotificationList) LoadIssues() error {
380
389
for _ , notification := range nl {
381
390
if notification .Issue == nil {
382
391
notification .Issue = issues [notification .IssueID ]
383
- if notification .Issue != nil {
384
- notification .Issue .Repo = notification .Repository
385
- }
392
+ notification .Issue .Repo = notification .Repository
386
393
}
387
394
}
388
395
return nil
389
396
}
390
397
391
- func (nl NotificationList ) getCommentIDs () []int64 {
398
+ func (nl NotificationList ) getPendingCommentIDs () []int64 {
392
399
var ids = make (map [int64 ]struct {}, len (nl ))
393
400
for _ , notification := range nl {
394
401
if notification .CommentID == 0 || notification .Comment != nil {
@@ -407,7 +414,7 @@ func (nl NotificationList) LoadComments() error {
407
414
return nil
408
415
}
409
416
410
- var commentIDs = nl .getCommentIDs ()
417
+ var commentIDs = nl .getPendingCommentIDs ()
411
418
var comments = make (map [int64 ]* Comment , len (commentIDs ))
412
419
var left = len (commentIDs )
413
420
for left > 0 {
@@ -441,9 +448,7 @@ func (nl NotificationList) LoadComments() error {
441
448
for _ , notification := range nl {
442
449
if notification .CommentID > 0 && notification .Comment == nil {
443
450
notification .Comment = comments [notification .CommentID ]
444
- if notification .Comment != nil {
445
- notification .Comment .Issue = notification .Issue
446
- }
451
+ notification .Comment .Issue = notification .Issue
447
452
}
448
453
}
449
454
return nil
0 commit comments