Skip to content

Commit

Permalink
Merge pull request #1413 from eeff/v2.4
Browse files Browse the repository at this point in the history
Pick to 2.4 fix(persist): refresh node and tag count when deleting nodes and groups
  • Loading branch information
fengzeroz authored Jul 25, 2023
2 parents 36cb4f6 + 0a21862 commit ccb6a62
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 ccb6a62

Please sign in to comment.