🐛 Fix flush reading anchor
This commit is contained in:
parent
bce86224bb
commit
6bedb3a17d
@ -4,7 +4,6 @@ import (
|
|||||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/database"
|
"git.solsynth.dev/hypernet/messaging/pkg/internal/database"
|
||||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
"git.solsynth.dev/hypernet/messaging/pkg/internal/models"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/samber/lo"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,19 +21,15 @@ func FlushReadingAnchor() {
|
|||||||
if len(readingAnchorQueue) == 0 {
|
if len(readingAnchorQueue) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
idSet := lo.Uniq(lo.Map(lo.Keys(readingAnchorQueue), func(item uint, _ int) uint {
|
|
||||||
return item
|
|
||||||
}))
|
|
||||||
var pairs []map[string]any
|
|
||||||
for k, v := range readingAnchorQueue {
|
for k, v := range readingAnchorQueue {
|
||||||
pairs = append(pairs, map[string]any{
|
|
||||||
"id": k,
|
|
||||||
"reading_anchor": gorm.Expr("GREATEST(reading_anchor, ?)", v),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if err := database.C.Model(&models.ChannelMember{}).
|
if err := database.C.Model(&models.ChannelMember{}).
|
||||||
Where("id IN ?", idSet).
|
Where("id = ?", k).
|
||||||
Updates(pairs).Error; err != nil {
|
Updates(map[string]any{
|
||||||
|
"reading_anchor": gorm.Expr("GREATEST(reading_anchor, ?)", v),
|
||||||
|
}).Error; err != nil {
|
||||||
log.Error().Err(err).Msg("An error occurred when flushing reading anchor...")
|
log.Error().Err(err).Msg("An error occurred when flushing reading anchor...")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
clear(readingAnchorQueue)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user