chiark / gitweb /
search.py waits for rescan to finish
[disorder] / server / choose.c
index d5bc52ebe9e63e9ac9d19af700bda8665cf723e3..06c9601b76e90a2b197961f34b7e915d0980ea0b 100644 (file)
@@ -153,7 +153,7 @@ static unsigned long compute_weight(const char *track,
   if((s = kvp_get(prefs, "played_time"))) {
     last = atoll(s);
     now = time(0);
-    if(now < last + 8 * 3600)       /* TODO configurable */
+    if(now < last + config->replay_min)
       return 0;
   }
 
@@ -173,6 +173,16 @@ static unsigned long compute_weight(const char *track,
   if(*required_tags && !tag_intersection(track_tags, required_tags))
     return 0;
 
+  /* Use the configured weight if available */
+  if((s = kvp_get(prefs, "weight"))) {
+    long n;
+    errno = 0;
+
+    n = strtol(s, 0, 10);
+    if((errno == 0 || errno == ERANGE) && n >= 0)
+      return n;
+  }
+  
   return 90000;
 }
 
@@ -182,11 +192,15 @@ static int collect_tracks_callback(const char *track,
                                    struct kvp *prefs,
                                   void attribute((unused)) *u,
                                   DB_TXN attribute((unused)) *tid) {
-  const unsigned long weight = compute_weight(track, data, prefs);
+  unsigned long weight = compute_weight(track, data, prefs);
 
   if(weight) {
     struct weighted_track *const t = xmalloc(sizeof *t);
 
+    /* Clamp weight so that we can fit in billions of tracks when we do
+     * arithmetic in long long */
+    if(weight > 0x7fffffff)
+      weight = 0x7fffffff;
     t->next = tracks;
     t->track = track;
     t->weight = weight;