aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-20 18:32:25 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-20 19:43:32 +0100
commitf76b1582238a3ee7f45308f1df4f840c21b946a8 (patch)
treeade86728e44d37eadd73ac588936b88eda6f69a2 /src/libstat
parent251a7c9d11a676a58f22edb8afd09f20c69bd61f (diff)
downloadrspamd-f76b1582238a3ee7f45308f1df4f840c21b946a8.tar.gz
rspamd-f76b1582238a3ee7f45308f1df4f840c21b946a8.zip
[Project] Adopt C modules and stuff
Diffstat (limited to 'src/libstat')
-rw-r--r--src/libstat/backends/redis_backend.c17
-rw-r--r--src/libstat/learn_cache/redis_cache.c17
2 files changed, 30 insertions, 4 deletions
diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c
index 74d8c3bf1..113e93df9 100644
--- a/src/libstat/backends/redis_backend.c
+++ b/src/libstat/backends/redis_backend.c
@@ -69,6 +69,7 @@ enum rspamd_redis_connection_state {
struct redis_stat_runtime {
struct redis_stat_ctx *ctx;
struct rspamd_task *task;
+ struct rspamd_symcache_item *item;
struct upstream *selected;
struct event timeout_event;
GArray *results;
@@ -1196,6 +1197,10 @@ rspamd_redis_processed (redisAsyncContext *c, gpointer r, gpointer priv)
}
if (rt->has_event) {
+ if (rt->item) {
+ rspamd_symcache_item_async_dec_check (task, rt->item);
+ }
+
rspamd_session_remove_event (task->s, rspamd_redis_fin, rt);
}
}
@@ -1228,6 +1233,10 @@ rspamd_redis_learned (redisAsyncContext *c, gpointer r, gpointer priv)
}
if (rt->has_event) {
+ if (rt->item) {
+ rspamd_symcache_item_async_dec_check (task, rt->item);
+ }
+
rspamd_session_remove_event (task->s, rspamd_redis_fin_learn, rt);
}
}
@@ -1594,7 +1603,9 @@ rspamd_redis_process_tokens (struct rspamd_task *task,
if (redisAsyncCommand (rt->redis, rspamd_redis_connected, rt, "HGET %s %s",
rt->redis_object_expanded, learned_key) == REDIS_OK) {
- rspamd_session_add_event (task->s, NULL, rspamd_redis_fin, rt, rspamd_redis_stat_quark ());
+ rspamd_session_add_event (task->s,
+ rspamd_redis_fin, rt, rspamd_redis_stat_quark ());
+ rt->item = rspamd_symbols_cache_get_cur_item (task);
rt->has_event = TRUE;
if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) {
@@ -1798,7 +1809,9 @@ rspamd_redis_learn_tokens (struct rspamd_task *task, GPtrArray *tokens,
"RSIG");
}
- rspamd_session_add_event (task->s, NULL, rspamd_redis_fin_learn, rt, rspamd_redis_stat_quark ());
+ rspamd_session_add_event (task->s,
+ rspamd_redis_fin_learn, rt, rspamd_redis_stat_quark ());
+ rt->item = rspamd_symbols_cache_get_cur_item (task);
rt->has_event = TRUE;
/* Set timeout */
diff --git a/src/libstat/learn_cache/redis_cache.c b/src/libstat/learn_cache/redis_cache.c
index 11bc13aae..789991186 100644
--- a/src/libstat/learn_cache/redis_cache.c
+++ b/src/libstat/learn_cache/redis_cache.c
@@ -41,6 +41,7 @@ struct rspamd_redis_cache_ctx {
struct rspamd_redis_cache_runtime {
struct rspamd_redis_cache_ctx *ctx;
struct rspamd_task *task;
+ struct rspamd_symcache_item *item;
struct upstream *selected;
struct event timeout_event;
redisAsyncContext *redis;
@@ -151,6 +152,9 @@ rspamd_stat_cache_redis_get (redisAsyncContext *c, gpointer r, gpointer priv)
}
if (rt->has_event) {
+ if (rt->item) {
+ rspamd_symcache_item_async_dec_check (task, rt->item);
+ }
rspamd_session_remove_event (task->s, rspamd_redis_cache_fin, rt);
}
}
@@ -173,6 +177,9 @@ rspamd_stat_cache_redis_set (redisAsyncContext *c, gpointer r, gpointer priv)
}
if (rt->has_event) {
+ if (rt->item) {
+ rspamd_symcache_item_async_dec_check (task, rt->item);
+ }
rspamd_session_remove_event (task->s, rspamd_redis_cache_fin, rt);
}
}
@@ -453,7 +460,11 @@ rspamd_stat_cache_redis_check (struct rspamd_task *task,
if (redisAsyncCommand (rt->redis, rspamd_stat_cache_redis_get, rt,
"HGET %s %s",
rt->ctx->redis_object, h) == REDIS_OK) {
- rspamd_session_add_event (task->s, NULL, rspamd_redis_cache_fin, rt, rspamd_stat_cache_redis_quark ());
+ rspamd_session_add_event (task->s,
+ rspamd_redis_cache_fin,
+ rt,
+ rspamd_stat_cache_redis_quark ());
+ rt->item = rspamd_symbols_cache_get_cur_item (task);
event_add (&rt->timeout_event, &tv);
rt->has_event = TRUE;
}
@@ -485,7 +496,9 @@ rspamd_stat_cache_redis_learn (struct rspamd_task *task,
if (redisAsyncCommand (rt->redis, rspamd_stat_cache_redis_set, rt,
"HSET %s %s %d",
rt->ctx->redis_object, h, flag) == REDIS_OK) {
- rspamd_session_add_event (task->s, NULL, rspamd_redis_cache_fin, rt, rspamd_stat_cache_redis_quark ());
+ rspamd_session_add_event (task->s,
+ rspamd_redis_cache_fin, rt, rspamd_stat_cache_redis_quark ());
+ rt->item = rspamd_symbols_cache_get_cur_item (task);
event_add (&rt->timeout_event, &tv);
rt->has_event = TRUE;
}