Refactor: show_range_start deals with extended fetch
[pazpar2-moved-to-github.git] / src / session.c
index cafbc9d..41bcb30 100644 (file)
@@ -1264,11 +1264,14 @@ int session_fetch_more(struct session *se)
 struct record_cluster **show_range_start(struct session *se,
                                          struct reclist_sortparms *sp,
                                          int start, int *num, int *total,
-                                         Odr_int *sumhits, Odr_int *approx_hits)
+                                         Odr_int *sumhits, Odr_int *approx_hits,
+                                         void (*show_records_ready)(void *data),
+                                         struct http_channel *chan)
 {
     struct record_cluster **recs = 0;
     struct reclist_sortparms *spp;
     struct client_list *l;
+    int num0 = *num;
     int i;
 #if USE_TIMING
     yaz_timing_t t = yaz_timing_create();
@@ -1324,6 +1327,29 @@ struct record_cluster **show_range_start(struct session *se,
             yaz_timing_get_sys(t));
     yaz_timing_destroy(&t);
 #endif
+    if (*num < num0)
+    {
+        session_log(se, YLOG_LOG,
+                    "Subset %d < %d retrieved for show", *num, num0);
+        if (!session_fetch_more(se))
+            session_log(se, YLOG_LOG, "can not fetch more");
+        else
+        {
+            show_range_stop(se, recs);
+            session_log(se, YLOG_LOG, "fetching more in progress");
+            if (session_set_watch(se, SESSION_WATCH_SHOW,
+                                  show_records_ready, chan, chan))
+            {
+                session_log(se, YLOG_WARN, "Ignoring show block");
+                session_enter(se, "show_range_start");
+            }
+            else
+            {
+                session_log(se, YLOG_LOG, "session watch OK");
+                return 0;
+            }
+        }
+    }
     return recs;
 }