From fe7206771852a37728cbdd4e1b76e2eb482980e7 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 4 Feb 2013 12:56:19 +0100 Subject: [PATCH] Refactor: show_range_start deals with extended fetch --- src/http_command.c | 27 +++------------------------ src/session.c | 28 +++++++++++++++++++++++++++- src/session.h | 5 +++-- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/http_command.c b/src/http_command.c index ecc1275..7620e92 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -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%d\n", active); diff --git a/src/session.c b/src/session.c index cafbc9d..41bcb30 100644 --- a/src/session.c +++ b/src/session.c @@ -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; } diff --git a/src/session.h b/src/session.h index be8a1cf..0b05afc 100644 --- a/src/session.h +++ b/src/session.h @@ -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); -- 1.7.10.4