File tree Expand file tree Collapse file tree 2 files changed +26
-20
lines changed
src/Simplex/Messaging/Server/QueueStore/Postgres Expand file tree Collapse file tree 2 files changed +26
-20
lines changed Original file line number Diff line number Diff line change @@ -321,7 +321,7 @@ BEGIN
321321 msg_queue_size = GREATEST(msg_queue_size - 1, 0)
322322 WHERE recipient_id = p_recipient_id;
323323 END IF;
324- ELSE
324+ ELSIF msg_deleted OR q_size != 0 THEN
325325 UPDATE msg_queues
326326 SET msg_can_write = TRUE, msg_queue_size = 0
327327 WHERE recipient_id = p_recipient_id;
@@ -391,15 +391,18 @@ BEGIN
391391 LOOP
392392 SELECT array_agg(recipient_id)
393393 INTO rids
394- FROM msg_queues
395- WHERE deleted_at IS NULL
396- AND updated_at > very_old_ts
397- AND msg_queue_size > 0
398- AND recipient_id > last_rid
399- ORDER BY recipient_id ASC
400- LIMIT batch_size;
401-
402- EXIT WHEN cardinality(rids) = 0;
394+ FROM (
395+ SELECT recipient_id
396+ FROM msg_queues
397+ WHERE deleted_at IS NULL
398+ AND updated_at > very_old_ts
399+ AND msg_queue_size > 0
400+ AND recipient_id > last_rid
401+ ORDER BY recipient_id ASC
402+ LIMIT batch_size
403+ ) qs;
404+
405+ EXIT WHEN rids IS NULL OR cardinality(rids) = 0;
403406
404407 FOREACH rid IN ARRAY rids
405408 LOOP
Original file line number Diff line number Diff line change @@ -72,15 +72,18 @@ BEGIN
7272 LOOP
7373 SELECT array_agg(recipient_id)
7474 INTO rids
75- FROM msg_queues
76- WHERE deleted_at IS NULL
77- AND updated_at > very_old_ts
78- AND msg_queue_size > 0
79- AND recipient_id > last_rid
80- ORDER BY recipient_id ASC
81- LIMIT batch_size;
82-
83- EXIT WHEN cardinality(rids) = 0 ;
75+ FROM (
76+ SELECT recipient_id
77+ FROM msg_queues
78+ WHERE deleted_at IS NULL
79+ AND updated_at > very_old_ts
80+ AND msg_queue_size > 0
81+ AND recipient_id > last_rid
82+ ORDER BY recipient_id ASC
83+ LIMIT batch_size
84+ ) qs;
85+
86+ EXIT WHEN rids IS NULL OR cardinality(rids) = 0 ;
8487
8588 FOREACH rid IN ARRAY rids
8689 LOOP
@@ -204,7 +207,7 @@ BEGIN
204207 msg_queue_size = GREATEST(msg_queue_size - 1 , 0 )
205208 WHERE recipient_id = p_recipient_id;
206209 END IF;
207- ELSE
210+ ELSIF msg_deleted OR q_size != 0 THEN
208211 UPDATE msg_queues
209212 SET msg_can_write = TRUE, msg_queue_size = 0
210213 WHERE recipient_id = p_recipient_id;
You can’t perform that action at this time.
0 commit comments