Fix bug with mq_latest_message where the wrong message may be returned

if multiple messages have the exact same creation date.
This commit is contained in:
Diggory Blake 2021-10-13 16:32:17 +01:00
parent 59adc6313f
commit 15cafb3590
No known key found for this signature in database
GPG key ID: E6BDFA83146ABD40
6 changed files with 71 additions and 3 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "sqlxmq"
version = "0.3.1"
version = "0.3.2"
authors = ["Diggory Blake <diggsey@googlemail.com>"]
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]

View file

@ -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;

View file

@ -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;

View file

@ -1,6 +1,6 @@
[package]
name = "sqlxmq_macros"
version = "0.3.1"
version = "0.3.2"
authors = ["Diggory Blake <diggsey@googlemail.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"

View file

@ -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;

View file

@ -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;