fix: handle backend issue list regressions
This commit is contained in:
@@ -3535,6 +3535,13 @@ func (t *Topic) replyGetData(sess *Session, asUid types.Uid, asChan bool, req *M
|
||||
} else if ok {
|
||||
messages = filterHotMessagesForUser(hotMessages, asUid)
|
||||
}
|
||||
} else if shouldTryHotMessageSupplement(t.cat, opts, len(messages)) {
|
||||
hotMessages, ok, cacheErr := store.GetHotMessages(t.tenantID, t.name, opts, hotMessageRangeLimit(opts))
|
||||
if cacheErr != nil {
|
||||
logs.Warn.Printf("get.data hot message supplement failed topic=%s user=%s: %v", t.name, asUid.UserId(), cacheErr)
|
||||
} else if ok {
|
||||
messages = mergeHotMessageSupplement(messages, filterHotMessagesForUser(hotMessages, asUid), opts)
|
||||
}
|
||||
}
|
||||
|
||||
// Push the list of messages to the client as {data}.
|
||||
@@ -3595,6 +3602,28 @@ func shouldTryHotMessageFallback(cat types.TopicCat, lastID int64, opts *types.Q
|
||||
return lastID <= 0 || opts.Since >= floor
|
||||
}
|
||||
|
||||
func shouldTryHotMessageSupplement(cat types.TopicCat, opts *types.QueryOpt, got int) bool {
|
||||
if cat != types.TopicCatGrp || opts == nil || opts.IfModifiedSince != nil ||
|
||||
!opts.User.IsZero() || opts.Topic != "" || len(opts.IdRanges) > 0 ||
|
||||
opts.Since <= 0 || opts.Before <= opts.Since {
|
||||
return false
|
||||
}
|
||||
expected := hotMessageRangeLimit(opts)
|
||||
return expected > 0 && got > 0 && got < expected
|
||||
}
|
||||
|
||||
func hotMessageRangeLimit(opts *types.QueryOpt) int {
|
||||
if opts == nil || opts.Since <= 0 || opts.Before <= opts.Since {
|
||||
return hotMessageFallbackLimit(opts)
|
||||
}
|
||||
expected := opts.Before - opts.Since
|
||||
limit := hotMessageFallbackLimit(opts)
|
||||
if limit <= 0 || int64(limit) > expected {
|
||||
return int(expected)
|
||||
}
|
||||
return limit
|
||||
}
|
||||
|
||||
func hotMessageFallbackLimit(opts *types.QueryOpt) int {
|
||||
if opts != nil && opts.Limit > 0 {
|
||||
return opts.Limit
|
||||
@@ -3602,6 +3631,36 @@ func hotMessageFallbackLimit(opts *types.QueryOpt) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func mergeHotMessageSupplement(messages, hotMessages []types.Message, opts *types.QueryOpt) []types.Message {
|
||||
if len(messages) == 0 || len(hotMessages) == 0 {
|
||||
return messages
|
||||
}
|
||||
bySeq := make(map[int64]types.Message, len(hotMessages)+len(messages))
|
||||
for _, msg := range hotMessages {
|
||||
bySeq[msg.SeqId] = msg
|
||||
}
|
||||
for _, msg := range messages {
|
||||
bySeq[msg.SeqId] = msg
|
||||
}
|
||||
merged := make([]types.Message, 0, len(bySeq))
|
||||
for _, msg := range bySeq {
|
||||
if opts != nil {
|
||||
if opts.Since > 0 && msg.SeqId < opts.Since {
|
||||
continue
|
||||
}
|
||||
if opts.Before > 0 && msg.SeqId >= opts.Before {
|
||||
continue
|
||||
}
|
||||
}
|
||||
merged = append(merged, msg)
|
||||
}
|
||||
sort.Slice(merged, func(i, j int) bool { return merged[i].SeqId > merged[j].SeqId })
|
||||
if opts != nil && opts.Limit > 0 && len(merged) > opts.Limit {
|
||||
merged = merged[:opts.Limit]
|
||||
}
|
||||
return merged
|
||||
}
|
||||
|
||||
func filterHotMessagesForUser(messages []types.Message, asUid types.Uid) []types.Message {
|
||||
if len(messages) == 0 {
|
||||
return messages
|
||||
|
||||
Reference in New Issue
Block a user