From aaff6cb1913acdc1cff06d5290e5fecb6a2d53c3 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 30 Jan 2014 11:46:31 +0100 Subject: [PATCH] memcached: take sorting into account for result set key --- src/zoom-memcached.c | 9 +++++++-- src/zoom-p.h | 1 + src/zoom-query.c | 12 +++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/zoom-memcached.c b/src/zoom-memcached.c index 250010c..570345a 100644 --- a/src/zoom-memcached.c +++ b/src/zoom-memcached.c @@ -80,7 +80,12 @@ void ZOOM_memcached_resultset(ZOOM_resultset r, ZOOM_query q) if (c->password) wrbuf_sha1_puts(r->mc_key, c->password, 1); wrbuf_puts(r->mc_key, ";"); - wrbuf_sha1_puts(r->mc_key, ZOOM_query_get_query_string(q), 1); + { + WRBUF w = wrbuf_alloc(); + ZOOM_query_get_hash(q, w); + wrbuf_sha1_puts(r->mc_key, wrbuf_cstr(w), 1); + wrbuf_destroy(w); + } wrbuf_puts(r->mc_key, ";"); #endif } @@ -132,7 +137,7 @@ void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset resultset) rc = memcached_set(c->mc_st, wrbuf_buf(resultset->mc_key),wrbuf_len(resultset->mc_key), str, strlen(str), expiration, flags); - yaz_log(YLOG_LOG, "Store SRU hit count key=%s value=%s rc=%u %s", + yaz_log(YLOG_LOG, "Store hit count key=%s value=%s rc=%u %s", wrbuf_cstr(resultset->mc_key), str, (unsigned) rc, memcached_last_error_message(c->mc_st)); } diff --git a/src/zoom-p.h b/src/zoom-p.h index f443594..27b1c85 100644 --- a/src/zoom-p.h +++ b/src/zoom-p.h @@ -252,6 +252,7 @@ Z_Query *ZOOM_query_get_Z_Query(ZOOM_query s); Z_SortKeySpecList *ZOOM_query_get_sortspec(ZOOM_query s); const char *ZOOM_query_get_query_string(ZOOM_query s); const char *ZOOM_query_get_sru11(ZOOM_query s); +void ZOOM_query_get_hash(ZOOM_query s, WRBUF w); int ZOOM_uri_to_code(const char *uri); diff --git a/src/zoom-query.c b/src/zoom-query.c index 0551cdb..2fc197d 100644 --- a/src/zoom-query.c +++ b/src/zoom-query.c @@ -147,6 +147,16 @@ const char *ZOOM_query_get_query_string(ZOOM_query s) return wrbuf_cstr(s->full_query); } +void ZOOM_query_get_hash(ZOOM_query s, WRBUF w) +{ + wrbuf_printf(w, "%d;", s->query_type); + if (s->query_string) + wrbuf_puts(w, s->query_string); + wrbuf_printf(w, ";%d;", s->sort_strategy); + if (s->sort_spec) + yaz_sort_spec_to_type7(s->sort_spec, w); +} + /* * Returns an xmalloc()d string containing RPN that corresponds to the * CQL passed in. On error, sets the Connection object's error state @@ -367,7 +377,7 @@ ZOOM_query_sortby2(ZOOM_query s, const char *strategy, const char *criteria) odr_reset(s->odr_sort_spec); s->sort_spec = yaz_sort_spec(s->odr_sort_spec, criteria); if (!s->sort_spec) - return -1; + return -2; return generate(s); } -- 1.7.10.4