From: Adam Dickmeiss Date: Tue, 22 Jan 2013 14:44:12 +0000 (+0100) Subject: Work on fetch more X-Git-Tag: v1.6.26~17 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=0198d9a410e2664e29f8fa526cf9bcf8f5bea89a;p=pazpar2-moved-to-github.git Work on fetch more --- diff --git a/src/client.c b/src/client.c index 0cf2e07..5f05633 100644 --- a/src/client.c +++ b/src/client.c @@ -762,6 +762,24 @@ static const char *get_strategy_plus_sort(struct client *l, const char *field) return strategy_plus_sort; } +int client_fetch_more(struct client *cl) +{ + int extra = cl->hits - cl->record_offset; + if (extra > 0) + { + ZOOM_resultset set = cl->resultset; + int max_extra = 10; + + if (extra > max_extra) + extra = max_extra; + + ZOOM_resultset_records(set, 0, cl->record_offset, extra); + client_set_state(cl, Client_Working); + return 1; + } + return 0; +} + int client_parse_init(struct client *cl, int same_search) { cl->same_search = same_search; diff --git a/src/client.h b/src/client.h index 8176db9..eeccf0f 100644 --- a/src/client.h +++ b/src/client.h @@ -80,6 +80,7 @@ int client_prep_connection(struct client *cl, iochan_man_t iochan, const struct timeval *abstime); int client_start_search(struct client *cl); +int client_fetch_more(struct client *cl); int client_parse_init(struct client *cl, int same_search); int client_parse_range(struct client *cl, const char *startrecs, const char *maxrecs); int client_parse_sort(struct client *cl, struct reclist_sortparms *sp); diff --git a/src/http_command.c b/src/http_command.c index f2f9b20..ecc1275 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -93,6 +93,8 @@ struct http_sessions { static YAZ_MUTEX g_http_session_mutex = 0; static int g_http_sessions = 0; +static void show_records_ready(void *data); + int get_version(struct http_request *rq) { const char *version = http_argbyname(rq, "version"); int version_no = 0; @@ -1118,7 +1120,31 @@ static void show_records(struct http_channel *c, struct http_session *s, int act } - rl = show_range_start(s->psession, sp, startn, &numn, &total, &total_hits, &approx_hits); + 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); + } response_open(c, "show"); wrbuf_printf(c->wrbuf, "\n%d\n", active); diff --git a/src/session.c b/src/session.c index b7fcfec..148f462 100644 --- a/src/session.c +++ b/src/session.c @@ -1234,6 +1234,38 @@ void show_single_stop(struct session *se, struct record_cluster *rec) } +int session_fetch_more(struct session *se) +{ + struct client_list *l; + int ret = 0; + + for (l = se->clients_active; l; l = l->next) + { + struct client *cl = l->client; + if (client_get_state(cl) == Client_Idle) + { + if (client_fetch_more(cl)) + { + session_log(se, YLOG_LOG, "%s: more to fetch", + client_get_id(cl)); + ret = 1; + } + else + { + session_log(se, YLOG_LOG, "%s: no more to fetch", + client_get_id(cl)); + } + } + else + { + session_log(se, YLOG_LOG, "%s: no fetch due to state=%s", + client_get_id(cl), client_get_state_str(cl)); + } + + } + return ret; +} + struct record_cluster **show_range_start(struct session *se, struct reclist_sortparms *sp, int start, int *num, int *total, diff --git a/src/session.h b/src/session.h index 66c41ba..be8a1cf 100644 --- a/src/session.h +++ b/src/session.h @@ -170,7 +170,11 @@ enum pazpar2_error_code session_search(struct session *s, const char *query, struct record_cluster **show_range_start(struct session *s, struct reclist_sortparms *sp, int start, - int *num, int *total, Odr_int *sumhits, Odr_int *approximation); + int *num, int *total, + Odr_int *sumhits, + Odr_int *approximation); + +int session_fetch_more(struct session *s); void show_range_stop(struct session *s, struct record_cluster **recs); struct record_cluster *show_single_start(struct session *s, const char *id,