From e81009ff5d95cdd09f37f244748cca0e5a84cc9c Mon Sep 17 00:00:00 2001 From: Jeesun Kim Date: Tue, 30 Jan 2018 18:48:24 +0900 Subject: [PATCH] fix bug: cleanup thread is not working Change-Id: I994d773dd777021fdee560af109dc4fdd19c6c0f --- server/cal_server_cleanup.h | 1 + server/db/cal_db.c | 5 ++++ server/db/cal_db_plugin_book.c | 54 ++++-------------------------------------- 3 files changed, 11 insertions(+), 49 deletions(-) diff --git a/server/cal_server_cleanup.h b/server/cal_server_cleanup.h index d422b79..bf8e256 100644 --- a/server/cal_server_cleanup.h +++ b/server/cal_server_cleanup.h @@ -21,5 +21,6 @@ void cal_server_cleanup_start(void); void cal_server_cleanup_end(void); +void cal_server_cleanup_send_signal(void); #endif /*__CAL_SERVER_CLEANUP_H__*/ diff --git a/server/db/cal_db.c b/server/db/cal_db.c index 97f777f..722f5f0 100644 --- a/server/db/cal_db.c +++ b/server/db/cal_db.c @@ -31,6 +31,7 @@ #include "cal_list.h" #include "cal_db.h" #include "cal_access_control.h" +#include "cal_server_cleanup.h" #include "cal_utils.h" #define BULK_DEFAULT_COUNT 100 @@ -472,6 +473,8 @@ int cal_db_delete_record(const char* view_uri, int id) else cal_db_util_end_trans(false); + cal_server_cleanup_send_signal(); + return ret; } @@ -858,6 +861,8 @@ int cal_db_delete_records(const char* view_uri, int record_id_array[], int count else cal_db_util_end_trans(false); + cal_server_cleanup_send_signal(); + return ret; } diff --git a/server/db/cal_db_plugin_book.c b/server/db/cal_db_plugin_book.c index 767398d..041ad85 100644 --- a/server/db/cal_db_plugin_book.c +++ b/server/db/cal_db_plugin_book.c @@ -300,62 +300,18 @@ static int _cal_db_book_delete_record(int id) { int ret = CALENDAR_ERROR_NONE; char query[CAL_DB_SQL_MAX_LEN] = {0}; - int calendar_book_id = -1; - snprintf(query, sizeof(query), "SELECT id FROM %s WHERE id = %d", - CAL_TABLE_CALENDAR, id); - ret = cal_db_util_query_get_first_int_result(query, NULL, &calendar_book_id); - if (CALENDAR_ERROR_NONE != ret) { - /* LCOV_EXCL_START */ - ERR("cal_db_util_query_get_first_int_result() Fail(%d)", ret); - return ret; - /* LCOV_EXCL_STOP */ - } - - int count = 0; - int count2 = 0; - snprintf(query, sizeof(query), "select count(*) from %s", CAL_TABLE_UTIME_INSTANCE); - ret = cal_db_util_query_get_first_int_result(query, NULL, &count); - if (CALENDAR_ERROR_NONE != ret) { - /* LCOV_EXCL_START */ - ERR("cal_db_util_query_get_first_int_result() Fail"); - return ret; - /* LCOV_EXCL_STOP */ - } - - snprintf(query, sizeof(query), "select count(*) from %s", CAL_TABLE_LOCALTIME_INSTANCE); - ret = cal_db_util_query_get_first_int_result(query, NULL, &count2); - if (CALENDAR_ERROR_NONE != ret) { - /* LCOV_EXCL_START */ - ERR("cal_db_util_query_get_first_int_result() Fail"); - return ret; - /* LCOV_EXCL_STOP */ - } - - count += count2; - - if (1000 < count) { - snprintf(query, sizeof(query), "UPDATE %s SET deleted = 1 WHERE id = %d", CAL_TABLE_CALENDAR, id); - ret = cal_db_util_query_exec(query); - RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_db_util_query_exec() Fail(%d)", ret); - cal_server_cleanup_start(); - } else { - snprintf(query, sizeof(query), "DELETE FROM %s WHERE id = %d", CAL_TABLE_CALENDAR, id); - ret = cal_db_util_query_exec(query); - RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_db_util_query_exec() Fail(%d)", ret); - - snprintf(query, sizeof(query), "DELETE FROM %s WHERE calendar_id = %d", CAL_TABLE_SCHEDULE, id); - ret = cal_db_util_query_exec(query); - RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_db_util_query_exec() Fail(%d)", ret); - } + snprintf(query, sizeof(query), "UPDATE %s SET deleted = 1 WHERE id = %d", CAL_TABLE_CALENDAR, id); + ret = cal_db_util_query_exec(query); + RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_db_util_query_exec() Fail(%d)", ret); - snprintf(query, sizeof(query), "DELETE FROM %s WHERE calendar_id = %d", CAL_TABLE_DELETED, id); + snprintf(query, sizeof(query), "DELETE FROM "CAL_TABLE_DELETED" WHERE calendar_id = %d", id); ret = cal_db_util_query_exec(query); RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_db_util_query_exec() Fail(%d)", ret); cal_access_control_reset(); - cal_db_util_notify(CAL_NOTI_TYPE_BOOK); + return CALENDAR_ERROR_NONE; } -- 2.7.4