import time, redis
from app.config import settings
from app.database import SessionLocal
from app.models.user import User
from app.routers import search as search_router
from app.routers import questions as q_router

db=SessionLocal(); user=db.query(User).filter(User.role=="admin").first()
r=redis.from_url(settings.REDIS_URL, decode_responses=True)

def run(label):
    t=time.perf_counter()
    res=search_router.search_everything(q="febrile seizure imaging", kinds=None, limit=10, db=db, current_user=user)
    ms=(time.perf_counter()-t)*1000
    counts={k:len(v) for k,v in res["results"].items()}
    bank=q_router.list_questions(q="febrile seizure imaging", db=db, current_user=user) if False else None
    print(f"{label:32s} {ms:6.0f}ms  {counts}  first-article={res['results']['article'][0]['title'] if res['results']['article'] else None}")

run("configured")
r.set("settings:rerank_model", "no-such-reranker")
run("model the proxy does not know")
r.set("settings:rerank_model", "")
run("switched off")
r.delete("settings:rerank_model")
run("back to the env default")
