mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: make summary items subquery unique by summary id
This commit is contained in:
parent
a1f6c2884b
commit
1a47243f70
@ -1,6 +1,7 @@
|
|||||||
package repositories
|
package repositories
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
datastructure "github.com/duke-git/lancet/v2/datastructure/set"
|
||||||
"github.com/muety/wakapi/models"
|
"github.com/muety/wakapi/models"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"time"
|
"time"
|
||||||
@ -78,20 +79,20 @@ func (r *SummaryRepository) DeleteByUser(userId string) error {
|
|||||||
// inplace
|
// inplace
|
||||||
func (r *SummaryRepository) populateItems(summaries []*models.Summary) error {
|
func (r *SummaryRepository) populateItems(summaries []*models.Summary) error {
|
||||||
summaryMap := map[uint]*models.Summary{}
|
summaryMap := map[uint]*models.Summary{}
|
||||||
summaryIds := make([]uint, len(summaries))
|
summaryIds := datastructure.NewSet[uint]()
|
||||||
for i, s := range summaries {
|
for _, s := range summaries {
|
||||||
if s.NumHeartbeats == 0 {
|
if s.NumHeartbeats == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
summaryMap[s.ID] = s
|
summaryMap[s.ID] = s
|
||||||
summaryIds[i] = s.ID
|
summaryIds.Add(s.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
var items []*models.SummaryItem
|
var items []*models.SummaryItem
|
||||||
|
|
||||||
if err := r.db.
|
if err := r.db.
|
||||||
Model(&models.SummaryItem{}).
|
Model(&models.SummaryItem{}).
|
||||||
Where("summary_id in ?", summaryIds).
|
Where("summary_id in ?", summaryIds.Values()).
|
||||||
Find(&items).Error; err != nil {
|
Find(&items).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user