Refactor: show_range_start deals with extended fetch
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 4 Feb 2013 11:56:19 +0000 (12:56 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 4 Feb 2013 11:56:19 +0000 (12:56 +0100)
src/http_command.c
src/session.c
src/session.h

index ecc1275..7620e92 100644 (file)
@@ -1120,31 +1120,10 @@ static void show_records(struct http_channel *c, struct http_session *s, int act
 
     }
 
-    i = numn;
     rl = show_range_start(s->psession, sp, startn, &numn, &total,
-                          &total_hits, &approx_hits);
-    if (i > numn)
-    {
-        show_range_stop(s->psession, rl);
-        session_log(s->psession, YLOG_LOG,
-                    "Subset %d < %d retrieved for show", numn, i);
-        if (!session_fetch_more(s->psession))
-            session_log(s->psession, YLOG_LOG, "can not fetch more");
-        else
-        {
-            session_log(s->psession, YLOG_LOG, "fetching more in progress");
-            if (session_set_watch(s->psession, SESSION_WATCH_SHOW,
-                                  show_records_ready, c, c))
-                session_log(s->psession, YLOG_WARN, "Ignoring show block");
-            else
-            {
-                session_log(s->psession, YLOG_LOG, "session watch OK");
-                return;
-            }
-        }
-        rl = show_range_start(s->psession, sp, startn, &numn, &total,
-                              &total_hits, &approx_hits);
-    }
+                          &total_hits, &approx_hits, show_records_ready, c);
+    if (!rl)
+        return;
 
     response_open(c, "show");
     wrbuf_printf(c->wrbuf, "\n<activeclients>%d</activeclients>\n", active);
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;
 }
 
index be8a1cf..0b05afc 100644 (file)
@@ -172,8 +172,9 @@ struct record_cluster **show_range_start(struct session *s,
                                          int start,
                                          int *num, int *total,
                                          Odr_int *sumhits,
-                                         Odr_int *approximation);
-
+                                         Odr_int *approximation,
+                                         void (*ready)(void *data),
+                                         struct http_channel *chan);
 int session_fetch_more(struct session *s);
 void show_range_stop(struct session *s, struct record_cluster **recs);