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