Some checks are pending
Backend tests / test (push) Waiting to run
- Szukanie w jednym serwisie do 60 tys. scen zaczyna od jego scen (scenes.id = ANY),
gdy fraza jest popularna albo bez trigramu: "sel" w hqporner 3,4 s -> 0,1 s, "brat"
w fullmoviesxxx 2,9 s -> 0,15 s. Rzadkie frazy dalej trigramami (GOON-75).
- Poprawka regresji z c08abf6: fraza bez trigramu przy zawezeniu po 3 s oddawala
pusta liste ("ai" w fullmoviesxxx: 0 wynikow). Teraz od serwisu albo limit 10 s.
- sort=studio z rzadka fraza: JOIN ze studiami i sort samych trafien zamiast
przejscia po 33 tys. studiow ("sunny leone" 928 s -> 0,26 s, "savanna" 20 s -> 0,17 s).
Porownanie ze starym kodem na 100 wyszukiwaniach w serwisach i 12 z sortem po studiu:
wyniki identyczne poza naprawionymi pustymi listami.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
82 lines
2.9 KiB
Python
82 lines
2.9 KiB
Python
from app.api.scenes import (
|
|
_SEARCH_WALK_BUDGET_MS,
|
|
_SEARCH_WALK_BUDGET_NO_TRGM_MS,
|
|
_SEARCH_WALK_BUDGET_NO_TRGM_NARROWED_MS,
|
|
_origin_driven_worth,
|
|
_rare_title_phrase,
|
|
_search_walk_budget,
|
|
)
|
|
|
|
# 1000 tytulow jak histogram z pg_stats: 20 z "anal", 1 z "hailey rose", reszta obojetna.
|
|
SAMPLE = ["anal scene %d" % i for i in range(20)] + ["hailey rose pov"] + [
|
|
"other title %d" % i for i in range(979)
|
|
]
|
|
|
|
|
|
def _budget(q, off=0, want=51, narrowed=False):
|
|
return _search_walk_budget(q, off, want, narrowed, lambda: SAMPLE)
|
|
|
|
|
|
def test_common_phrase_walks():
|
|
# 20/1000 = 2%: na strone 1 trzeba przejsc ~2,5 tys. scen
|
|
assert _budget("anal") == _SEARCH_WALK_BUDGET_MS
|
|
|
|
|
|
def test_phrase_absent_from_sample_goes_to_trigrams():
|
|
assert _budget("jackerman") is None
|
|
|
|
|
|
def test_single_hit_phrase_goes_to_trigrams():
|
|
# 1/1000 = 0,1%: ~51 tys. scen do przejscia, powyzej progu
|
|
assert _budget("hailey rose") is None
|
|
|
|
|
|
def test_deep_page_of_common_phrase_goes_to_trigrams():
|
|
# strona 13 "anal": (600 + 51) / 2% = ~32 tys.
|
|
assert _budget("anal", off=600) is None
|
|
|
|
|
|
def test_narrowed_search_goes_to_trigrams():
|
|
assert _budget("anal", narrowed=True) is None
|
|
|
|
|
|
def test_short_phrase_always_walks():
|
|
# bez trigramu zwykly plan czyta caly indeks; tez przy zawezeniu i poza probka
|
|
for q in ("vo", "q", "xz", " a "):
|
|
assert _budget(q) == _SEARCH_WALK_BUDGET_NO_TRGM_MS
|
|
assert _budget("zq", off=5000) == _SEARCH_WALK_BUDGET_NO_TRGM_MS
|
|
|
|
|
|
def test_short_phrase_narrowed_gets_longer_budget():
|
|
# z tagiem trafienia sa rzadsze; po 3 s oddawalismy pusta liste mimo wynikow
|
|
assert _budget("ai", narrowed=True) == _SEARCH_WALK_BUDGET_NO_TRGM_NARROWED_MS
|
|
|
|
|
|
def test_sample_not_read_when_not_needed():
|
|
def boom():
|
|
raise AssertionError("probka niepotrzebna")
|
|
|
|
assert _search_walk_budget("vo", 0, 51, False, boom) == _SEARCH_WALK_BUDGET_NO_TRGM_MS
|
|
assert _search_walk_budget("vo", 0, 51, True, boom) == _SEARCH_WALK_BUDGET_NO_TRGM_NARROWED_MS
|
|
assert _search_walk_budget("anal", 0, 51, True, boom) is None
|
|
|
|
|
|
def test_origin_driven_for_common_and_short_phrases():
|
|
# "anal" 20/1000 w probce: popularna, w malym serwisie zaczynamy od jego scen
|
|
assert _origin_driven_worth("anal", lambda: SAMPLE)
|
|
# bez trigramu zawsze od serwisu (inaczej przejscie po calym katalogu)
|
|
assert _origin_driven_worth("ai", lambda: SAMPLE)
|
|
|
|
|
|
def test_origin_driven_skipped_for_rare_phrases():
|
|
# nazwisko: trigramy znajda kilka scen szybciej niz tablica id serwisu
|
|
assert not _origin_driven_worth("hailey rose", lambda: SAMPLE)
|
|
assert not _origin_driven_worth("jackerman", lambda: SAMPLE)
|
|
|
|
|
|
def test_rare_phrase_detection():
|
|
assert _rare_title_phrase("hailey rose", lambda: SAMPLE)
|
|
assert _rare_title_phrase("sunny leone", lambda: SAMPLE)
|
|
assert not _rare_title_phrase("anal", lambda: SAMPLE)
|
|
# bez trigramu nie jest "rzadka": trigramy i tak by jej nie znalazly
|
|
assert not _rare_title_phrase("ai", lambda: SAMPLE)
|