Skip to content

Commit

Permalink
fix(persist): refresh node and tag count when deleting nodes and groups
Browse files Browse the repository at this point in the history
  • Loading branch information
eeff committed Jul 25, 2023
1 parent 36cb4f6 commit 0a21862
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/persist/persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,9 @@ static inline int node_count_load()

if (SQLITE_OK == sqlite3_prepare_v2(global_db, query, -1, &stmt, NULL) &&
SQLITE_ROW == sqlite3_step(stmt)) {
pthread_rwlock_wrlock(&global_rwlock);
global_node_count = sqlite3_column_int(stmt, 0);
pthread_rwlock_unlock(&global_rwlock);
} else {
rv = -1;
}
Expand All @@ -503,7 +505,9 @@ static inline int tag_count_load()

if (SQLITE_OK == sqlite3_prepare_v2(global_db, query, -1, &stmt, NULL) &&
SQLITE_ROW == sqlite3_step(stmt)) {
pthread_rwlock_wrlock(&global_rwlock);
global_tag_count = sqlite3_column_int(stmt, 0);
pthread_rwlock_unlock(&global_rwlock);
} else {
rv = -1;
}
Expand Down Expand Up @@ -668,6 +672,7 @@ int neu_persister_delete_node(const char *node_name)
execute_sql(global_db, "DELETE FROM nodes WHERE name=%Q;", node_name);
if (0 == rv) {
node_count_add(-1);
tag_count_load();
}
return rv;
}
Expand Down Expand Up @@ -1192,9 +1197,13 @@ int neu_persister_load_groups(const char *driver_name, UT_array **group_infos)
int neu_persister_delete_group(const char *driver_name, const char *group_name)
{
// rely on foreign key constraints to delete tags and subscriptions
return execute_sql(global_db,
"DELETE FROM groups WHERE driver_name=%Q AND name=%Q",
driver_name, group_name);
int rv = execute_sql(global_db,
"DELETE FROM groups WHERE driver_name=%Q AND name=%Q",
driver_name, group_name);
if (0 == rv) {
tag_count_load();
}
return rv;
}

int neu_persister_store_node_setting(const char *node_name, const char *setting)
Expand Down

0 comments on commit 0a21862

Please sign in to comment.