Skip to content

Commit

Permalink
Bail early if we did not match anything
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Apr 2, 2024
1 parent 953e2b0 commit 346bd95
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions server/filestore.go
Expand Up @@ -2286,6 +2286,10 @@ func (mb *msgBlock) firstMatching(filter string, wc bool, start uint64, sm *Stor
subs = append(subs, subj)
}
}
// Check if we matched anything
if len(subs) == 0 {
return nil, didLoad, ErrStoreMsgNotFound
}
}
fseq = lseq + 1
for _, subj := range subs {
Expand All @@ -2304,17 +2308,17 @@ func (mb *msgBlock) firstMatching(filter string, wc bool, start uint64, sm *Stor
}
}

if fseq > lseq {
return nil, didLoad, ErrStoreMsgNotFound
}

// If we guess to not do a linear scan, but the above resulted in alot of subs that will
// need to be checked for every scanned message, revert.
// TODO(dlc) - we could memoize the subs across calls.
if len(subs) > int(lseq-fseq) {
doLinearScan = true
}

if fseq > lseq {
return nil, didLoad, ErrStoreMsgNotFound
}

// Need messages loaded from here on out.
if mb.cacheNotLoaded() {
if err := mb.loadMsgsWithLock(); err != nil {
Expand Down

0 comments on commit 346bd95

Please sign in to comment.