fix(gemini-web): Correct ambiguity check in conversation lookup

This commit is contained in:
hkfires
2025-09-29 21:40:25 +08:00
parent 6080527e9e
commit 1d70336a91
3 changed files with 185 additions and 174 deletions

View File

@@ -108,6 +108,8 @@ func LookupMatch(hash string) (MatchRecord, bool, error) {
return MatchRecord{}, false, err return MatchRecord{}, false, err
} }
var foundOne bool var foundOne bool
var ambiguous bool
var firstLabel string
var single MatchRecord var single MatchRecord
err = db.View(func(tx *bolt.Tx) error { err = db.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte(bucketMatches)) bucket := tx.Bucket([]byte(bucketMatches))
@@ -129,12 +131,18 @@ func LookupMatch(hash string) (MatchRecord, bool, error) {
if strings.TrimSpace(rec.AccountLabel) == "" || rec.PrefixLen <= 0 { if strings.TrimSpace(rec.AccountLabel) == "" || rec.PrefixLen <= 0 {
continue continue
} }
if foundOne { label := strings.ToLower(strings.TrimSpace(rec.AccountLabel))
// More than one distinct label exists for this hash; ambiguous. if !foundOne {
return nil firstLabel = label
}
single = rec single = rec
foundOne = true foundOne = true
continue
}
if label != firstLabel {
ambiguous = true
// Early exit scan; ambiguity detected.
return nil
}
} }
if foundOne { if foundOne {
return nil return nil
@@ -149,6 +157,9 @@ func LookupMatch(hash string) (MatchRecord, bool, error) {
if err != nil { if err != nil {
return MatchRecord{}, false, err return MatchRecord{}, false, err
} }
if ambiguous {
return MatchRecord{}, false, nil
}
if strings.TrimSpace(single.AccountLabel) == "" || single.PrefixLen <= 0 { if strings.TrimSpace(single.AccountLabel) == "" || single.PrefixLen <= 0 {
return MatchRecord{}, false, nil return MatchRecord{}, false, nil
} }