Skip to content
Snippets Groups Projects
Commit 2a274e58 authored by Bartek Wrona's avatar Bartek Wrona
Browse files

Fixed bug related to no last-read case (and processing null block number at further parts of query)

parent 43bba05e
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!348get_number_of_unread_notifications speedup
...@@ -24,7 +24,7 @@ $BODY$ ...@@ -24,7 +24,7 @@ $BODY$
DECLARE DECLARE
__account_id INT := 0; __account_id INT := 0;
__last_read_at TIMESTAMP; __last_read_at TIMESTAMP;
__last_read_at_block INT; __last_read_at_block hive_blocks.num%TYPE;
__limit_block hive_blocks.num%TYPE = block_before_head( '90 days' ); __limit_block hive_blocks.num%TYPE = block_before_head( '90 days' );
BEGIN BEGIN
__account_id = find_account_id( _account, True ); __account_id = find_account_id( _account, True );
...@@ -33,11 +33,13 @@ BEGIN ...@@ -33,11 +33,13 @@ BEGIN
FROM hive_accounts ha FROM hive_accounts ha
WHERE ha.id = __account_id; WHERE ha.id = __account_id;
SELECT hb.num INTO __last_read_at_block --- Warning given account can have no last_read_at set, so lets fallback to the block limit to avoid comparison to NULL.
FROM hive_blocks hb SELECT COALESCE((SELECT hb.num
WHERE hb.created_at <= __last_read_at FROM hive_blocks hb
ORDER by hb.created_at desc WHERE hb.created_at <= __last_read_at
LIMIT 1; ORDER by hb.created_at desc
LIMIT 1), __limit_block)
INTO __last_read_at_block;
RETURN QUERY SELECT RETURN QUERY SELECT
__last_read_at as lastread_at, __last_read_at as lastread_at,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment