Skip to content
Snippets Groups Projects
Commit 32e0d434 authored by Andrzej Lisak's avatar Andrzej Lisak
Browse files

[ABW]: removed duplicate (and slightly wrong) follow related SQL functions

added missing .sql files to upgrade script
parent 1180f5e1
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!337reusing code of bridge calls in condenser_api
......@@ -604,9 +604,6 @@ def setup(db):
"condenser_get_by_feed_with_reblog.sql",
"condenser_get_by_blog.sql",
"bridge_get_account_posts_by_blog.sql",
"condenser_get_follow_counts.sql",
"condenser_get_names_by_followers.sql",
"condenser_get_names_by_following.sql",
"condenser_get_names_by_reblogged.sql",
"condenser_get_discussions_by_comments.sql",
"condenser_get_account_reputations.sql"
......
DROP FUNCTION IF EXISTS condenser_get_follow_counts;
CREATE FUNCTION condenser_get_follow_counts( in _account VARCHAR )
RETURNS TABLE(
following hive_accounts.following%TYPE,
followers hive_accounts.followers%TYPE
)
AS
$function$
DECLARE
BEGIN
RETURN QUERY SELECT
ha.following, ha.followers
FROM hive_accounts ha
WHERE ha.name = _account;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_names_by_followers;
CREATE FUNCTION condenser_get_names_by_followers( in _account VARCHAR, in _start_account VARCHAR, in _state SMALLINT, _limit SMALLINT )
RETURNS TABLE(
names hive_accounts.name%TYPE
)
AS
$function$
DECLARE
__account_id INT := find_account_id( _account, True );
__start_account_id INT := 0;
__created_at TIMESTAMP;
BEGIN
IF _start_account <> '' THEN
__start_account_id = find_account_id( _start_account, True );
END IF;
IF __start_account_id <> 0 THEN
SELECT hf.created_at
INTO __created_at
FROM hive_follows hf
WHERE hf.following = __account_id AND hf.follower = __start_account_id;
END IF;
RETURN QUERY SELECT
name
FROM hive_follows hf
LEFT JOIN hive_accounts ha ON hf.follower = ha.id
WHERE hf.following = __account_id
AND state = _state
AND ( __start_account_id = 0 OR hf.created_at <= __created_at )
ORDER BY hf.created_at DESC
LIMIT _limit;
END
$function$
language plpgsql STABLE;
DROP FUNCTION IF EXISTS condenser_get_names_by_following;
CREATE FUNCTION condenser_get_names_by_following( in _account VARCHAR, in _start_account VARCHAR, in _state SMALLINT, _limit SMALLINT )
RETURNS TABLE(
names hive_accounts.name%TYPE
)
AS
$function$
DECLARE
__account_id INT := find_account_id( _account, True );
__start_account_id INT := 0;
__created_at TIMESTAMP;
BEGIN
IF _start_account <> '' THEN
__start_account_id = find_account_id( _start_account, True );
END IF;
IF __start_account_id <> 0 THEN
SELECT hf.created_at
INTO __created_at
FROM hive_follows hf
WHERE hf.follower = __account_id AND hf.following = __start_account_id;
END IF;
RETURN QUERY SELECT
name
FROM hive_follows hf
LEFT JOIN hive_accounts ha ON hf.following = ha.id
WHERE hf.follower = __account_id
AND state = _state
AND ( __start_account_id = 0 OR hf.created_at <= __created_at )
ORDER BY hf.created_at DESC
LIMIT _limit;
END
$function$
language plpgsql STABLE;
......@@ -41,14 +41,10 @@ for sql in postgres_handle_view_changes.sql \
condenser_api_post_ex_type.sql \
condenser_get_blog.sql \
condenser_get_content.sql \
condenser_get_discussions_by_created.sql \
condenser_get_discussions_by_blog.sql \
condenser_tags.sql \
condenser_follows.sql \
hot_and_trends.sql \
condenser_get_discussions_by_trending.sql \
condenser_get_discussions_by_hot.sql \
condenser_get_discussions_by_promoted.sql \
condenser_get_post_discussions_by_payout.sql \
condenser_get_comment_discussions_by_payout.sql \
update_hive_posts_children_count.sql \
update_hive_posts_api_helper.sql \
database_api_list_comments.sql \
......@@ -61,14 +57,13 @@ for sql in postgres_handle_view_changes.sql \
condenser_get_by_feed_with_reblog.sql \
condenser_get_by_blog.sql \
bridge_get_account_posts_by_blog.sql \
condenser_get_follow_counts.sql \
condenser_get_names_by_followers.sql \
condenser_get_names_by_following.sql \
condenser_get_names_by_reblogged.sql
condenser_get_names_by_reblogged.sql \
condenser_get_discussions_by_comments.sql \
condenser_get_account_reputations.sql
do
echo Executing psql -U $1 -d $2 -f $sql
time psql -1 -v "ON_ERROR_STOP=1" -U $1 -d $2 -c '\timing' -f $sql 2>&1 | tee -a -i upgrade.log
echo Executing psql -U $1 -d $2 -f $sql
time psql -1 -v "ON_ERROR_STOP=1" -U $1 -d $2 -c '\timing' -f $sql 2>&1 | tee -a -i upgrade.log
echo $?
done
......
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