Bläddra i källkod

fix: with_hour bug

Dew-OF-Aurora 3 veckor sedan
förälder
incheckning
03782b0194
2 ändrade filer med 12 tillägg och 10 borttagningar
  1. 1 1
      config.server.json
  2. 11 9
      scripts/domain_updater.py

+ 1 - 1
config.server.json

@@ -77,7 +77,7 @@
       }
     ],
     "prefer_lower": true,
-    "within_hours": 24,
+    "within_hours": 0,
     "tie_breakers": [
       {
         "field": "created_at",

+ 11 - 9
scripts/domain_updater.py

@@ -436,9 +436,9 @@ def validate_config(cfg):
         if strategy not in {"weighted_average", "lexicographic"}:
             raise ValueError("scoring.strategy must be 'weighted_average' or 'lexicographic'")
 
-        within_hours = to_float_or_none(scoring.get("within_hours", 24))
-        if within_hours is None or within_hours <= 0:
-            raise ValueError("scoring.within_hours must be a positive number")
+        within_hours = to_float_or_none(scoring.get("within_hours", 0))
+        if within_hours is None or within_hours < 0:
+            raise ValueError("scoring.within_hours must be a non-negative number (0 = disabled)")
 
         if strategy == "weighted_average":
             weighted_fields = scoring.get("weighted_fields")
@@ -721,16 +721,18 @@ def rank_scored_records(records, scoring_cfg):
     if not records:
         return []
 
-    within_hours = float(scoring_cfg.get("within_hours", 24))
+    within_hours = float(scoring_cfg.get("within_hours", 0))
     strategy = str(scoring_cfg.get("strategy", "weighted_average")).strip()
     prefer_lower = bool(scoring_cfg.get("prefer_lower", False))
     tie_breakers = scoring_cfg.get("tie_breakers", [])
 
-    now = dt.datetime.now(dt.timezone.utc)
-    cutoff = now - dt.timedelta(hours=within_hours)
-
-    recent = [r for r in records if r.get("created_at") is not None and r["created_at"] >= cutoff]
-    candidates = recent if recent else records
+    if within_hours > 0:
+        now = dt.datetime.now(dt.timezone.utc)
+        cutoff = now - dt.timedelta(hours=within_hours)
+        recent = [r for r in records if r.get("created_at") is not None and r["created_at"] >= cutoff]
+        candidates = recent if recent else records
+    else:
+        candidates = records
 
     default_lex_order = "asc" if prefer_lower else "desc"