Add slow DAAP queries to cache automatically

This commit is contained in:
ejurgensen
2014-08-24 01:23:23 +02:00
parent cf091e8d8b
commit 31ef4d4e13
5 changed files with 201 additions and 63 deletions

View File

@@ -34,9 +34,11 @@
#include <limits.h>
#include <stdint.h>
#include <inttypes.h>
#include <time.h>
#include <ctype.h>
#include <uninorm.h>
#include <unistd.h>
#include <avl.h>
@@ -2525,10 +2527,13 @@ daap_request(struct evhttp_request *req)
struct evbuffer *evbuf;
struct evkeyvalq query;
struct evkeyvalq *headers;
struct timespec start;
struct timespec end;
const char *ua;
cfg_t *lib;
char *libname;
char *passwd;
int msec;
int handler;
int ret;
int i;
@@ -2690,8 +2695,19 @@ daap_request(struct evhttp_request *req)
evhttp_parse_query(full_uri, &query);
clock_gettime(CLOCK_MONOTONIC, &start);
daap_handlers[handler].handler(req, evbuf, uri_parts, &query, ua);
clock_gettime(CLOCK_MONOTONIC, &end);
msec = (end.tv_sec * 1000 + end.tv_nsec / 1000000) - (start.tv_sec * 1000 + start.tv_nsec / 1000000);
DPRINTF(E_DBG, L_DB, "DAAP request handled in %d milliseconds\n", msec);
if (msec > daapcache_threshold())
daapcache_add(full_uri, ua);
evhttp_clear_headers(&query);
evbuffer_free(evbuf);
free(uri);