-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with
mq_latest_message
where the wrong message may be returned
if multiple messages have the exact same creation date.
- Loading branch information
Showing
6 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "sqlxmq" | ||
version = "0.3.1" | ||
version = "0.3.2" | ||
authors = ["Diggory Blake <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
|
@@ -23,7 +23,7 @@ uuid = { version = "0.8.2", features = ["v4"] } | |
log = "0.4.14" | ||
serde_json = "1.0.64" | ||
serde = "1.0.124" | ||
sqlxmq_macros = { version = "0.3.1", path = "sqlxmq_macros" } | ||
sqlxmq_macros = { version = "0.3.2", path = "sqlxmq_macros" } | ||
anymap2 = "0.13.0" | ||
|
||
[features] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CREATE OR REPLACE FUNCTION mq_latest_message(from_channel_name TEXT, from_channel_args TEXT) | ||
RETURNS UUID AS $$ | ||
SELECT COALESCE( | ||
( | ||
SELECT id FROM mq_msgs | ||
WHERE channel_name = from_channel_name | ||
AND channel_args = from_channel_args | ||
AND after_message_id IS NOT NULL | ||
AND id != uuid_nil() | ||
ORDER BY created_at DESC, id DESC | ||
LIMIT 1 | ||
), | ||
uuid_nil() | ||
) | ||
$$ LANGUAGE SQL STABLE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
CREATE OR REPLACE FUNCTION mq_latest_message(from_channel_name TEXT, from_channel_args TEXT) | ||
RETURNS UUID AS $$ | ||
SELECT COALESCE( | ||
( | ||
SELECT id FROM mq_msgs | ||
WHERE channel_name = from_channel_name | ||
AND channel_args = from_channel_args | ||
AND after_message_id IS NOT NULL | ||
AND id != uuid_nil() | ||
AND NOT EXISTS( | ||
SELECT * FROM mq_msgs AS mq_msgs2 | ||
WHERE mq_msgs2.after_message_id = mq_msgs.id | ||
) | ||
ORDER BY created_at DESC | ||
LIMIT 1 | ||
), | ||
uuid_nil() | ||
) | ||
$$ LANGUAGE SQL STABLE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "sqlxmq_macros" | ||
version = "0.3.1" | ||
version = "0.3.2" | ||
authors = ["Diggory Blake <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
|
15 changes: 15 additions & 0 deletions
15
sqlxmq_stress/migrations/20211013151757_fix_mq_latest_message.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CREATE OR REPLACE FUNCTION mq_latest_message(from_channel_name TEXT, from_channel_args TEXT) | ||
RETURNS UUID AS $$ | ||
SELECT COALESCE( | ||
( | ||
SELECT id FROM mq_msgs | ||
WHERE channel_name = from_channel_name | ||
AND channel_args = from_channel_args | ||
AND after_message_id IS NOT NULL | ||
AND id != uuid_nil() | ||
ORDER BY created_at DESC, id DESC | ||
LIMIT 1 | ||
), | ||
uuid_nil() | ||
) | ||
$$ LANGUAGE SQL STABLE; |
19 changes: 19 additions & 0 deletions
19
sqlxmq_stress/migrations/20211013151757_fix_mq_latest_message.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
CREATE OR REPLACE FUNCTION mq_latest_message(from_channel_name TEXT, from_channel_args TEXT) | ||
RETURNS UUID AS $$ | ||
SELECT COALESCE( | ||
( | ||
SELECT id FROM mq_msgs | ||
WHERE channel_name = from_channel_name | ||
AND channel_args = from_channel_args | ||
AND after_message_id IS NOT NULL | ||
AND id != uuid_nil() | ||
AND NOT EXISTS( | ||
SELECT * FROM mq_msgs AS mq_msgs2 | ||
WHERE mq_msgs2.after_message_id = mq_msgs.id | ||
) | ||
ORDER BY created_at DESC | ||
LIMIT 1 | ||
), | ||
uuid_nil() | ||
) | ||
$$ LANGUAGE SQL STABLE; |