p3: no Tavily daily cap for restricted callers
Restricted searches skip the cap check. Credits land on tavily:restricted so they never raise the fleet row. Fleet at cap still falls through.
This commit is contained in:
@@ -99,7 +99,7 @@ func (e *Engine) Run(ctx context.Context, query string, k int, doRerank bool, ca
|
||||
class = dcache.ClassFleet
|
||||
}
|
||||
|
||||
attempted := e.attemptedNames()
|
||||
attempted := e.attemptedNames(class)
|
||||
key := dcache.SearchKey(query, attempted, k, e.now(), class)
|
||||
if b, ok := e.Cache.GetSearch(key); ok {
|
||||
var hits []Hit
|
||||
@@ -123,7 +123,7 @@ func (e *Engine) Run(ctx context.Context, query string, k int, doRerank bool, ca
|
||||
var wg sync.WaitGroup
|
||||
for i, src := range e.Sources {
|
||||
name := src.Name()
|
||||
if name == NameTavily && e.tavilyCapped() {
|
||||
if name == NameTavily && e.tavilyCapped(class) {
|
||||
outs[i] = one{name: name, out: SourceOut{Warn: "tavily: daily cap"}, skip: true}
|
||||
e.addCapped(NameTavily)
|
||||
continue
|
||||
@@ -164,7 +164,7 @@ func (e *Engine) Run(ctx context.Context, query string, k int, doRerank bool, ca
|
||||
if o.out.Credits > 0 {
|
||||
e.addCredits(caller, o.name, o.out.Credits)
|
||||
if o.name == NameTavily && e.Cache != nil {
|
||||
e.Cache.AddSearchCredits(NameTavily, e.now().UTC().Format("2006-01-02"), o.out.Credits)
|
||||
e.Cache.AddSearchCredits(tavilyCapSource(class), e.now().UTC().Format("2006-01-02"), o.out.Credits)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,10 +190,10 @@ func (e *Engine) Run(ctx context.Context, query string, k int, doRerank bool, ca
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Engine) attemptedNames() []string {
|
||||
func (e *Engine) attemptedNames(class string) []string {
|
||||
var n []string
|
||||
for _, s := range e.Sources {
|
||||
if s.Name() == NameTavily && e.tavilyCapped() {
|
||||
if s.Name() == NameTavily && e.tavilyCapped(class) {
|
||||
continue
|
||||
}
|
||||
n = append(n, s.Name())
|
||||
@@ -202,10 +202,20 @@ func (e *Engine) attemptedNames() []string {
|
||||
return n
|
||||
}
|
||||
|
||||
func (e *Engine) tavilyCapped() bool {
|
||||
func tavilyCapSource(class string) string {
|
||||
if class == dcache.ClassRestricted {
|
||||
return NameTavily + ":restricted"
|
||||
}
|
||||
return NameTavily
|
||||
}
|
||||
|
||||
func (e *Engine) tavilyCapped(class string) bool {
|
||||
if e == nil || e.TavilyCap <= 0 {
|
||||
return false
|
||||
}
|
||||
if class == dcache.ClassRestricted {
|
||||
return false
|
||||
}
|
||||
n := 0
|
||||
if e.Cache != nil {
|
||||
n = e.Cache.GetSearchCredits(NameTavily, e.now().UTC().Format("2006-01-02"))
|
||||
|
||||
Reference in New Issue
Block a user