Avoid cache regeneration triggering during db_query_run (in case the query is long running, like db_files_update_songalbumid might be)
This commit is contained in:
parent
335517a2e8
commit
879c2ef350
73
src/cache.c
73
src/cache.c
|
@ -103,6 +103,7 @@ struct stash
|
|||
|
||||
// After being triggered wait 60 seconds before rebuilding cache
|
||||
static struct timeval g_wait = { 60, 0 };
|
||||
static int g_suspended;
|
||||
|
||||
// The user may configure a threshold (in msec), and queries slower than
|
||||
// that will have their reply cached
|
||||
|
@ -936,6 +937,30 @@ cache_daap_update_timer(struct cache_command *cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
cache_daap_suspend_timer(struct cache_command *cmd)
|
||||
{
|
||||
if (!g_cacheev)
|
||||
return -1;
|
||||
|
||||
g_suspended = evtimer_pending(g_cacheev, NULL);
|
||||
if (g_suspended)
|
||||
evtimer_del(g_cacheev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
cache_daap_resume_timer(struct cache_command *cmd)
|
||||
{
|
||||
if (!g_cacheev)
|
||||
return -1;
|
||||
|
||||
if (g_suspended)
|
||||
evtimer_add(g_cacheev, &g_wait);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates cached timestamps to current time for all cache entries for the given path, if the file was not modfied
|
||||
|
@ -1404,6 +1429,54 @@ cache_daap_trigger(void)
|
|||
nonblock_command(cmd);
|
||||
}
|
||||
|
||||
void
|
||||
cache_daap_suspend(void)
|
||||
{
|
||||
struct cache_command *cmd;
|
||||
|
||||
if (!g_initialized)
|
||||
return;
|
||||
|
||||
cmd = (struct cache_command *)malloc(sizeof(struct cache_command));
|
||||
if (!cmd)
|
||||
{
|
||||
DPRINTF(E_LOG, L_CACHE, "Could not allocate cache_command\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(cmd, 0, sizeof(struct cache_command));
|
||||
|
||||
cmd->nonblock = 1;
|
||||
|
||||
cmd->func = cache_daap_suspend_timer;
|
||||
|
||||
nonblock_command(cmd);
|
||||
}
|
||||
|
||||
void
|
||||
cache_daap_resume(void)
|
||||
{
|
||||
struct cache_command *cmd;
|
||||
|
||||
if (!g_initialized)
|
||||
return;
|
||||
|
||||
cmd = (struct cache_command *)malloc(sizeof(struct cache_command));
|
||||
if (!cmd)
|
||||
{
|
||||
DPRINTF(E_LOG, L_CACHE, "Could not allocate cache_command\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(cmd, 0, sizeof(struct cache_command));
|
||||
|
||||
cmd->nonblock = 1;
|
||||
|
||||
cmd->func = cache_daap_resume_timer;
|
||||
|
||||
nonblock_command(cmd);
|
||||
}
|
||||
|
||||
int
|
||||
cache_daap_get(const char *query, struct evbuffer *evbuf)
|
||||
{
|
||||
|
|
|
@ -15,6 +15,12 @@
|
|||
void
|
||||
cache_daap_trigger(void);
|
||||
|
||||
void
|
||||
cache_daap_suspend(void);
|
||||
|
||||
void
|
||||
cache_daap_resume(void);
|
||||
|
||||
int
|
||||
cache_daap_get(const char *query, struct evbuffer *evbuf);
|
||||
|
||||
|
|
5
src/db.c
5
src/db.c
|
@ -1589,6 +1589,9 @@ db_query_run(char *query, int free, int cache_update)
|
|||
|
||||
DPRINTF(E_DBG, L_DB, "Running query '%s'\n", query);
|
||||
|
||||
/* If the query will be long running we don't want the cache to start regenerating */
|
||||
cache_daap_suspend();
|
||||
|
||||
ret = db_exec(query, &errmsg);
|
||||
if (ret != SQLITE_OK)
|
||||
DPRINTF(E_LOG, L_DB, "Error '%s' while runnning '%s'\n", errmsg, query);
|
||||
|
@ -1600,6 +1603,8 @@ db_query_run(char *query, int free, int cache_update)
|
|||
|
||||
if (cache_update)
|
||||
cache_daap_trigger();
|
||||
else
|
||||
cache_daap_resume();
|
||||
|
||||
return ((ret != SQLITE_OK) ? -1 : 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue