Skip to content
Extraits de code Groupes Projets
Vérifiée Valider daa46f15 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Use the init function for search add and search insert commands

parent 0fc43780
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!71Resolve "Performance of search commands"
...@@ -88,23 +88,26 @@ struct lkt_search { ...@@ -88,23 +88,26 @@ struct lkt_search {
lkt_add_queue, lkt_add_queue,
} type; } type;
bool (*init)(volatile sqlite3 *); /* Called at the end of the init phase */ void (*init)(void); /* Called at the end of the init phase */
void (*call)(void); /* Called during the iter phase, casted */ void (*call)(void); /* Called during the iter phase, casted */
struct lkt_state *srv; struct lkt_state *srv;
size_t c; size_t c;
long continuation; /* The continuation state of the client */ long continuation; /* The continuation state of the client */
int msg_count; /* How much messages we can send */ int msg_count; /* How much messages we can send */
const char *name; /* Stickers and playlists */ const char *name; /* Stickers and playlists */
union { union {
int qu_priority; /* Can be used... where the priority is needed! */ int qu_priority; /* Can be used... where the priority is needed! */
int st_value; /* The value of a sticker */ int st_value; /* The value of a sticker */
}; };
int st_uri; /* URI of a sticker */ int st_uri; /* URI of a sticker */
struct lkt_uri *qu_uri; /* Kara uri for a queue init function */
}; };
typedef bool (*lkt_search_init_add_func)(volatile sqlite3 *, struct lkt_uri *, int);
typedef bool (*lkt_search_database_func)(struct lkt_state *srv, size_t c, int id, int id_len, const char *row); typedef bool (*lkt_search_database_func)(struct lkt_state *srv, size_t c, int id, int id_len, const char *row);
typedef bool (*lkt_search_queue_func) (struct lkt_state *srv, size_t c, int id, int id_len, const char *row);
typedef bool (*lkt_search_sticker_func) (struct lkt_state *srv, size_t c, const char *sticker, const char *type, int uri, int value); typedef bool (*lkt_search_sticker_func) (struct lkt_state *srv, size_t c, const char *sticker, const char *type, int uri, int value);
bool database_search_database_init(volatile sqlite3 *db, char *col_name, char *rgx, struct lkt_search *ret); bool database_search_database_init(volatile sqlite3 *db, char *col_name, char *rgx, struct lkt_search *ret);
......
...@@ -420,10 +420,16 @@ __find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], lo ...@@ -420,10 +420,16 @@ __find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], lo
break; break;
case LKT_FND_ACT_ENQUEUE: case LKT_FND_ACT_ENQUEUE:
search.call = (void(*)(void)) lkt_callback_send_row_v2; search.call = (void(*)(void)) lkt_callback_send_row_v2;
search.init = (void(*)(void)) database_queue_add_uri;
search.type = lkt_add_queue;
search.qu_priority = 5;
srv->mpd_idle_events |= MPD_IDLE_PLAYLIST; srv->mpd_idle_events |= MPD_IDLE_PLAYLIST;
break; break;
case LKT_FND_ACT_ADD: case LKT_FND_ACT_ADD:
search.call = (void(*)(void)) lkt_callback_send_row_v2; search.call = (void(*)(void)) lkt_callback_send_row_v2;
search.init = (void(*)(void)) database_queue_add_uri;
search.qu_priority = 1;
search.type = lkt_add_queue;
srv->mpd_idle_events |= MPD_IDLE_PLAYLIST; srv->mpd_idle_events |= MPD_IDLE_PLAYLIST;
break; break;
default: default:
...@@ -433,8 +439,7 @@ __find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], lo ...@@ -433,8 +439,7 @@ __find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], lo
/* Select the right column */ /* Select the right column */
mpd_tag = cmd_args[0]; mpd_tag = cmd_args[0];
if (!strcasecmp("any", mpd_tag) || !strcasecmp("all", mpd_tag) || !strcasecmp("query", mpd_tag))
if (!strcasecmp("any", mpd_tag) || !strcasecmp("all", mpd_tag) || !strcasecmp("a", mpd_tag))
col_name = LKT_DATABASE_KARA_COLUMNT_ANY; col_name = LKT_DATABASE_KARA_COLUMNT_ANY;
else if (!strcasecmp("author", mpd_tag)) else if (!strcasecmp("author", mpd_tag))
col_name = LKT_DATABASE_NAME_KAUTHOR; col_name = LKT_DATABASE_NAME_KAUTHOR;
......
...@@ -11,16 +11,16 @@ ...@@ -11,16 +11,16 @@
static inline bool static inline bool
__init_search(volatile sqlite3 *db, struct lkt_search *ret) __init_search(volatile sqlite3 *db, struct lkt_search *ret)
{ {
UNUSED(db); bool sta = false;
switch (ret->type) { switch (ret->type) {
case lkt_add_queue: case lkt_add_queue:
/* Use the add uri */ sta = ((lkt_search_init_add_func) ret->init)(db, ret->qu_uri, ret->qu_priority);
return false; ret->type = lkt_search_queue;
default: default:
LOG_WARN_SCT("DB", "Init for type %d is not implemented", ret->type); LOG_WARN_SCT("DB", "Init for type %d is not implemented", ret->type);
return false; return false;
} }
return false; return sta;
} }
bool bool
...@@ -145,6 +145,10 @@ database_search_iter(struct lkt_search *item) ...@@ -145,6 +145,10 @@ database_search_iter(struct lkt_search *item)
id_len = sqlite3_column_int(item->stmt, 2); id_len = sqlite3_column_int(item->stmt, 2);
return ((lkt_search_database_func) item->call)(item->srv, item->c, id, id_len, sql_row); return ((lkt_search_database_func) item->call)(item->srv, item->c, id, id_len, sql_row);
case lkt_search_queue: case lkt_search_queue:
id = sqlite3_column_int(item->stmt, 0);
sql_row = (const char *) sqlite3_column_text(item->stmt, 1);
id_len = sqlite3_column_int(item->stmt, 2);
return ((lkt_search_queue_func) item->call)(item->srv, item->c, id, id_len, sql_row);
case lkt_search_playlist: case lkt_search_playlist:
default: default:
LOG_WARN_SCT("DB", "Search operation %d is not implemented", item->type); LOG_WARN_SCT("DB", "Search operation %d is not implemented", item->type);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter