Compare commits

..

No commits in common. "9698ea0c37fda34e65813fdacde972a2bcc9c5a6" and "33ae585879834d91797e982621ac78b42cae8adc" have entirely different histories.

4 changed files with 36 additions and 34 deletions

View File

@ -516,31 +516,32 @@ database_iterator_t *database_create_document_iterator(database_t *db) {
CRASH_IF_NOT_SQLITE_OK( CRASH_IF_NOT_SQLITE_OK(
sqlite3_prepare_v2( sqlite3_prepare_v2(
db->db, db->db,
"WITH doc (id, j) AS (" "WITH doc (j) AS (SELECT CASE"
"SELECT" " WHEN emb.embedding IS NULL THEN"
" document.id," " json_set(document.json_data, "
" json_set(document.json_data," " '$._id', document.id, "
" '$._id', document.id," " '$.size', document.size, "
" '$.index', (SELECT id FROM descriptor)," " '$.mtime', document.mtime, "
" '$.size', document.size," " '$.mime', mim.name,"
" '$.mtime', document.mtime," " '$.thumbnail', document.thumbnail_count, "
" '$.mime', mim.name," " '$.tag', json_group_array((SELECT tag FROM tag WHERE document.id = tag.id)))"
" '$.thumbnail', document.thumbnail_count," " ELSE"
" '$.tag', json_group_array(t.tag))" " json_set(document.json_data,"
" '$._id', document.id,"
" '$.size', document.size,"
" '$.mtime', document.mtime,"
" '$.mime', mim.name,"
" '$.thumbnail', document.thumbnail_count, "
" '$.tag', json_group_array((SELECT tag FROM tag WHERE document.id = tag.id)),"
" '$.emb', json_group_object(m.path, json(emb_to_json(emb.embedding))),"
" '$.embedding', 1)"
" END"
" FROM document" " FROM document"
" LEFT JOIN mime mim ON mim.id = document.mime" " LEFT JOIN embedding emb ON document.id = emb.id"
" LEFT JOIN tag t ON t.id = document.id"
" GROUP BY document.id)"
"SELECT CASE"
" WHEN emb.embedding IS NULL THEN j"
" ELSE json_set(j,"
" '$.emb', json_group_object(m.path, json(emb_to_json(emb.embedding))),"
" '$.embedding', 1"
" ) END"
" FROM doc"
" LEFT JOIN embedding emb ON doc.id = emb.id"
" LEFT JOIN model m ON emb.model_id = m.id" " LEFT JOIN model m ON emb.model_id = m.id"
" GROUP BY doc.id", " LEFT JOIN mime mim ON mim.id = document.mime"
" GROUP BY document.id)"
" SELECT json_set(j, '$.index', (SELECT id FROM descriptor)) FROM doc",
-1, &stmt, NULL)); -1, &stmt, NULL));
database_iterator_t *iter = malloc(sizeof(database_iterator_t)); database_iterator_t *iter = malloc(sizeof(database_iterator_t));

View File

@ -105,6 +105,7 @@ typedef struct database {
sqlite3_stmt *fts_write_tag_stmt; sqlite3_stmt *fts_write_tag_stmt;
sqlite3_stmt *fts_model_size; sqlite3_stmt *fts_model_size;
char **tag_array; char **tag_array;
database_ipc_ctx_t *ipc_ctx; database_ipc_ctx_t *ipc_ctx;

View File

@ -51,11 +51,11 @@
#include <ctype.h> #include <ctype.h>
#include "git_hash.h" #include "git_hash.h"
#define VERSION "3.3.2" #define VERSION "3.3.0"
static const char *const Version = VERSION; static const char *const Version = VERSION;
static const int VersionMajor = 3; static const int VersionMajor = 3;
static const int VersionMinor = 3; static const int VersionMinor = 3;
static const int VersionPatch = 2; static const int VersionPatch = 1;
#ifndef SIST_PLATFORM #ifndef SIST_PLATFORM
#define SIST_PLATFORM unknown #define SIST_PLATFORM unknown

View File

@ -77,14 +77,14 @@ static void worker_thread_loop(tpool_t *pool) {
job_t *job = database_get_work(ProcData.ipc_db, pool->shm->job_type); job_t *job = database_get_work(ProcData.ipc_db, pool->shm->job_type);
if (job != NULL) { if (job != NULL) {
if (pool->shm->stop) {
break;
}
pthread_mutex_lock(&(pool->shm->data_mutex)); pthread_mutex_lock(&(pool->shm->data_mutex));
pool->shm->busy_count += 1; pool->shm->busy_count += 1;
pthread_mutex_unlock(&(pool->shm->data_mutex)); pthread_mutex_unlock(&(pool->shm->data_mutex));
if (pool->shm->stop) {
break;
}
if (job->type == JOB_PARSE_JOB) { if (job->type == JOB_PARSE_JOB) {
parse(job->parse_job); parse(job->parse_job);
} else if (job->type == JOB_BULK_LINE) { } else if (job->type == JOB_BULK_LINE) {
@ -200,11 +200,11 @@ static void *tpool_worker(void *arg) {
pool->shm->ipc_ctx.completed_job_count += 1; pool->shm->ipc_ctx.completed_job_count += 1;
pthread_mutex_unlock(&(pool->shm->ipc_ctx.mutex)); pthread_mutex_unlock(&(pool->shm->ipc_ctx.mutex));
if (WIFSIGNALED(status)) { pthread_mutex_lock(&(pool->shm->data_mutex));
pthread_mutex_lock(&(pool->shm->data_mutex)); pool->shm->busy_count -= 1;
pool->shm->busy_count -= 1; pthread_mutex_unlock(&(pool->shm->data_mutex));
pthread_mutex_unlock(&(pool->shm->data_mutex));
if (WIFSIGNALED(status)) {
int crashed_thread_id = -1; int crashed_thread_id = -1;
for (int i = 0; i < MAX_THREADS; i++) { for (int i = 0; i < MAX_THREADS; i++) {
if (pool->shm->thread_id_to_pid_mapping[i] == pid) { if (pool->shm->thread_id_to_pid_mapping[i] == pid) {
@ -265,7 +265,7 @@ void tpool_wait(tpool_t *pool) {
if (pool->shm->ipc_ctx.job_count > 0) { if (pool->shm->ipc_ctx.job_count > 0) {
pthread_cond_wait(&(pool->shm->done_working_cond), &pool->shm->mutex); pthread_cond_wait(&(pool->shm->done_working_cond), &pool->shm->mutex);
} else { } else {
if (pool->shm->ipc_ctx.job_count == 0 && pool->shm->busy_count <= 0) { if (pool->shm->ipc_ctx.job_count == 0 && pool->shm->busy_count == 0) {
pool->shm->stop = TRUE; pool->shm->stop = TRUE;
break; break;
} }