Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hivemind
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
52
Issues
52
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
hive
hivemind
Commits
934f2316
Commit
934f2316
authored
Nov 19, 2020
by
Dan Notestein
1
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'jsalyers-more-community-muting-changes' into 'develop'
Jsalyers more community muting changes See merge request
!392
parents
5f1f94e1
7ecf23e7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
92 additions
and
35 deletions
+92
-35
hive/db/schema.py
hive/db/schema.py
+1
-0
hive/db/sql_scripts/bridge_get_discussion.sql
hive/db/sql_scripts/bridge_get_discussion.sql
+5
-2
hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql
hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql
+18
-7
hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql
...db/sql_scripts/bridge_get_ranked_post_for_communities.sql
+27
-12
hive/db/sql_scripts/bridge_get_ranked_post_for_observer_communities.sql
...ripts/bridge_get_ranked_post_for_observer_communities.sql
+6
-7
hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql
hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql
+18
-7
hive/db/sql_scripts/db_upgrade.sh
hive/db/sql_scripts/db_upgrade.sh
+1
-0
hive/db/sql_scripts/hive_muted_accounts_by_id_view.sql
hive/db/sql_scripts/hive_muted_accounts_by_id_view.sql
+16
-0
No files found.
hive/db/schema.py
View file @
934f2316
...
...
@@ -564,6 +564,7 @@ def setup(db):
"hive_posts_view.sql"
,
"hive_votes_view.sql"
,
"hive_muted_accounts_view.sql"
,
"hive_muted_accounts_by_id_view.sql"
,
"hive_post_operations.sql"
,
"head_block_time.sql"
,
"update_feed_cache.sql"
,
...
...
hive/db/sql_scripts/bridge_get_discussion.sql
View file @
934f2316
...
...
@@ -11,8 +11,10 @@ AS
$
function
$
DECLARE
__post_id
INT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
RETURN
QUERY
SELECT
hpv
.
id
,
...
...
@@ -60,13 +62,14 @@ BEGIN
SELECT
hp
.
id
,
hp
.
parent_id
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp
.
author_id
))
UNION
ALL
SELECT
children
.
id
,
children
.
parent_id
FROM
hive_posts
children
JOIN
child_posts
ON
children
.
parent_id
=
child_posts
.
id
JOIN
hive_accounts
ON
children
.
author_id
=
hive_accounts
.
id
WHERE
children
.
counter_deleted
=
0
AND
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hive_accounts
.
name
)
ELSE
True
END
)
WHERE
children
.
counter_deleted
=
0
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
children
.
author_id
)
)
)
SELECT
hp2
.
id
FROM
hive_posts
hp2
...
...
hive/db/sql_scripts/bridge_get_ranked_post_for_all.sql
View file @
934f2316
...
...
@@ -5,8 +5,10 @@ AS
$
function
$
DECLARE
__post_id
INT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
RETURN
QUERY
SELECT
hp
.
id
,
hp
.
author
,
...
...
@@ -52,11 +54,11 @@ BEGIN
FROM
hive_posts
hp1
JOIN
hive_accounts_view
ha
ON
hp1
.
author_id
=
ha
.
id
WHERE
hp1
.
counter_deleted
=
0
AND
hp1
.
depth
=
0
AND
NOT
ha
.
is_grayed
AND
(
__post_id
=
0
OR
hp1
.
id
<
__post_id
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
hp1
.
id
DESC
LIMIT
_limit
)
as
created
JOIN
hive_posts_view
hp
ON
hp
.
id
=
created
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
ORDER
BY
created
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -71,8 +73,10 @@ $function$
DECLARE
__post_id
INT
;
__hot_limit
FLOAT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
IF
__post_id
<>
0
THEN
SELECT
hp
.
sc_hot
INTO
__hot_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
...
...
@@ -123,11 +127,11 @@ BEGIN
hive_posts
hp1
WHERE
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
depth
=
0
AND
(
__post_id
=
0
OR
hp1
.
sc_hot
<
__hot_limit
OR
(
hp1
.
sc_hot
=
__hot_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
hp1
.
sc_hot
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
hot
JOIN
hive_posts_view
hp
ON
hp
.
id
=
hot
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
ORDER
BY
hot
.
hot
DESC
,
hot
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -199,7 +203,6 @@ BEGIN
LIMIT
_limit
)
as
payout
JOIN
hive_posts_view
hp
ON
hp
.
id
=
payout
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
ORDER
BY
payout
.
all_payout
DESC
,
payout
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -214,8 +217,10 @@ $function$
DECLARE
__post_id
INT
;
__payout_limit
hive_posts
.
payout
%
TYPE
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
IF
__post_id
<>
0
THEN
SELECT
(
hp
.
payout
+
hp
.
pending_payout
)
INTO
__payout_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
...
...
@@ -266,11 +271,11 @@ BEGIN
hive_posts
hp1
WHERE
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
depth
>
0
AND
(
__post_id
=
0
OR
(
hp1
.
payout
+
hp1
.
pending_payout
)
<
__payout_limit
OR
(
(
hp1
.
payout
+
hp1
.
pending_payout
)
=
__payout_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
(
hp1
.
payout
+
hp1
.
pending_payout
)
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
payout
JOIN
hive_posts_view
hp
ON
hp
.
id
=
payout
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
ORDER
BY
payout
.
all_payout
DESC
,
payout
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -286,8 +291,10 @@ DECLARE
__post_id
INT
;
__payout_limit
hive_posts
.
payout
%
TYPE
;
__head_block_time
TIMESTAMP
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
IF
__post_id
<>
0
THEN
SELECT
(
hp
.
payout
+
hp
.
pending_payout
)
INTO
__payout_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
...
...
@@ -340,11 +347,11 @@ BEGIN
WHERE
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
(
(
NOT
_bridge_api
AND
hp1
.
depth
=
0
)
OR
(
_bridge_api
AND
hp1
.
payout_at
BETWEEN
__head_block_time
+
interval
'12 hours'
AND
__head_block_time
+
interval
'36 hours'
)
)
AND
(
__post_id
=
0
OR
(
hp1
.
payout
+
hp1
.
pending_payout
)
<
__payout_limit
OR
(
(
hp1
.
payout
+
hp1
.
pending_payout
)
=
__payout_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
(
hp1
.
payout
+
hp1
.
pending_payout
)
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
payout
JOIN
hive_posts_view
hp
ON
hp
.
id
=
payout
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
ORDER
BY
payout
.
all_payout
DESC
,
payout
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -359,8 +366,10 @@ $function$
DECLARE
__post_id
INT
;
__promoted_limit
hive_posts
.
promoted
%
TYPE
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
IF
__post_id
<>
0
THEN
SELECT
hp
.
promoted
INTO
__promoted_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
...
...
@@ -411,11 +420,11 @@ BEGIN
hive_posts
hp1
WHERE
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
promoted
>
0
AND
(
__post_id
=
0
OR
hp1
.
promoted
<
__promoted_limit
OR
(
hp1
.
promoted
=
__promoted_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
hp1
.
promoted
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
promoted
JOIN
hive_posts_view
hp
ON
hp
.
id
=
promoted
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
ORDER
BY
promoted
.
promoted
DESC
,
promoted
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -430,8 +439,10 @@ $function$
DECLARE
__post_id
INT
;
__trending_limit
FLOAT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
IF
__post_id
<>
0
THEN
SELECT
hp
.
sc_trend
INTO
__trending_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
...
...
@@ -482,11 +493,11 @@ BEGIN
hive_posts
hp1
WHERE
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
depth
=
0
AND
(
__post_id
=
0
OR
hp1
.
sc_trend
<
__trending_limit
OR
(
hp1
.
sc_trend
=
__trending_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
hp1
.
sc_trend
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
trends
JOIN
hive_posts_view
hp
ON
hp
.
id
=
trends
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
ORDER
BY
trends
.
trend
DESC
,
trends
.
id
DESC
LIMIT
_limit
;
END
...
...
hive/db/sql_scripts/bridge_get_ranked_post_for_communities.sql
View file @
934f2316
...
...
@@ -3,7 +3,11 @@ CREATE FUNCTION bridge_get_ranked_post_pinned_for_community( in _community VARCH
RETURNS
SETOF
bridge_api_post
AS
$
function
$
SELECT
DECLARE
__observer_id
INT
;
BEGIN
__observer_id
=
find_account_id
(
_observer
,
False
);
RETURN
QUERY
SELECT
hp
.
id
,
hp
.
author
,
hp
.
parent_author
,
...
...
@@ -45,11 +49,12 @@ $function$
hive_posts_view
hp
JOIN
hive_communities
hc
ON
hc
.
id
=
hp
.
community_id
WHERE
hc
.
name
=
_community
AND
hp
.
is_pinned
AND
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp
.
author_id
)
)
ORDER
BY
hp
.
id
DESC
LIMIT
_limit
;
END
$
function
$
language
sql
STABLE
;
language
plpg
sql
STABLE
;
DROP
FUNCTION
IF
EXISTS
bridge_get_ranked_post_by_trends_for_community
;
CREATE
FUNCTION
bridge_get_ranked_post_by_trends_for_community
(
in
_community
VARCHAR
,
in
_author
VARCHAR
,
in
_permlink
VARCHAR
,
in
_limit
SMALLINT
,
in
_bridge_api
BOOLEAN
,
in
_observer
VARCHAR
)
...
...
@@ -59,8 +64,10 @@ $function$
DECLARE
__post_id
INT
;
__trending_limit
FLOAT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
IF
__post_id
<>
0
THEN
SELECT
hp
.
sc_trend
INTO
__trending_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
...
...
@@ -113,11 +120,11 @@ BEGIN
WHERE
hc
.
name
=
_community
AND
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
depth
=
0
AND
(
NOT
_bridge_api
OR
NOT
hp1
.
is_pinned
)
-- concatenated with bridge_get_ranked_post_pinned_for_community when called for bridge_api
AND
(
__post_id
=
0
OR
hp1
.
sc_trend
<
__trending_limit
OR
(
hp1
.
sc_trend
=
__trending_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
hp1
.
sc_trend
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
trends
JOIN
hive_posts_view
hp
ON
hp
.
id
=
trends
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
trends
.
trend
DESC
,
trends
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -132,8 +139,10 @@ $function$
DECLARE
__post_id
INT
;
__promoted_limit
hive_posts
.
promoted
%
TYPE
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
IF
__post_id
<>
0
THEN
SELECT
hp
.
promoted
INTO
__promoted_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
...
...
@@ -185,11 +194,11 @@ BEGIN
JOIN
hive_communities
hc
ON
hp1
.
community_id
=
hc
.
id
WHERE
hc
.
name
=
_community
AND
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
promoted
>
0
AND
(
__post_id
=
0
OR
hp1
.
promoted
<
__promoted_limit
OR
(
hp1
.
promoted
=
__promoted_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
hp1
.
promoted
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
promoted
JOIN
hive_posts_view
hp
ON
hp
.
id
=
promoted
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
promoted
.
promoted
DESC
,
promoted
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -205,8 +214,10 @@ DECLARE
__post_id
INT
;
__payout_limit
hive_posts
.
payout
%
TYPE
;
__head_block_time
TIMESTAMP
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
IF
__post_id
<>
0
THEN
SELECT
(
hp
.
payout
+
hp
.
pending_payout
)
INTO
__payout_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
...
...
@@ -259,11 +270,11 @@ BEGIN
JOIN
hive_communities
hc
ON
hp1
.
community_id
=
hc
.
id
WHERE
hc
.
name
=
_community
AND
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
payout_at
BETWEEN
__head_block_time
+
interval
'12 hours'
AND
__head_block_time
+
interval
'36 hours'
AND
(
__post_id
=
0
OR
(
hp1
.
payout
+
hp1
.
pending_payout
)
<
__payout_limit
OR
(
(
hp1
.
payout
+
hp1
.
pending_payout
)
=
__payout_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
(
hp1
.
payout
+
hp1
.
pending_payout
)
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
payout
JOIN
hive_posts_view
hp
ON
hp
.
id
=
payout
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
payout
.
all_payout
DESC
,
payout
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -278,8 +289,10 @@ $function$
DECLARE
__post_id
INT
;
__payout_limit
hive_posts
.
payout
%
TYPE
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
IF
__post_id
<>
0
THEN
SELECT
(
hp
.
payout
+
hp
.
pending_payout
)
INTO
__payout_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
...
...
@@ -331,11 +344,11 @@ BEGIN
JOIN
hive_communities
hc
ON
hp1
.
community_id
=
hc
.
id
WHERE
hc
.
name
=
_community
AND
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
depth
>
0
AND
(
__post_id
=
0
OR
(
hp1
.
payout
+
hp1
.
pending_payout
)
<
__payout_limit
OR
(
(
hp1
.
payout
+
hp1
.
pending_payout
)
=
__payout_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
(
hp1
.
payout
+
hp1
.
pending_payout
)
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
payout
JOIN
hive_posts_view
hp
ON
hp
.
id
=
payout
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
payout
.
all_payout
DESC
,
payout
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -408,7 +421,6 @@ BEGIN
LIMIT
_limit
)
as
payout
JOIN
hive_posts_view
hp
ON
hp
.
id
=
payout
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
payout
.
all_payout
DESC
,
payout
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -423,8 +435,10 @@ $function$
DECLARE
__post_id
INT
;
__hot_limit
FLOAT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
IF
__post_id
<>
0
THEN
SELECT
hp
.
sc_hot
INTO
__hot_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
...
...
@@ -476,11 +490,11 @@ BEGIN
JOIN
hive_communities
hc
ON
hp1
.
community_id
=
hc
.
id
WHERE
hc
.
name
=
_community
AND
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
depth
=
0
AND
(
__post_id
=
0
OR
hp1
.
sc_hot
<
__hot_limit
OR
(
hp1
.
sc_hot
=
__hot_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
hp1
.
sc_hot
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
hot
JOIN
hive_posts_view
hp
ON
hp
.
id
=
hot
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
hot
.
hot
DESC
,
hot
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -494,8 +508,10 @@ AS
$
function
$
DECLARE
__post_id
INT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
RETURN
QUERY
SELECT
hp
.
id
,
hp
.
author
,
...
...
@@ -541,15 +557,14 @@ BEGIN
FROM
hive_posts
hp1
JOIN
hive_communities
hc
ON
hp1
.
community_id
=
hc
.
id
JOIN
hive_accounts_view
ha
ON
hp1
.
author_id
=
ha
.
id
WHERE
hc
.
name
=
_community
AND
hp1
.
counter_deleted
=
0
AND
hp1
.
depth
=
0
AND
(
NOT
_bridge_api
OR
NOT
hp1
.
is_pinned
)
-- concatenated with bridge_get_ranked_post_pinned_for_community when called for bridge_api
AND
NOT
ha
.
is_grayed
AND
(
__post_id
=
0
OR
hp1
.
id
<
__post_id
)
AND
(
__post_id
=
0
OR
hp1
.
id
<
__post_id
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
hp1
.
id
DESC
LIMIT
_limit
)
as
created
JOIN
hive_posts_view
hp
ON
hp
.
id
=
created
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
created
.
id
DESC
LIMIT
_limit
;
END
...
...
hive/db/sql_scripts/bridge_get_ranked_post_for_observer_communities.sql
View file @
934f2316
...
...
@@ -52,7 +52,7 @@ BEGIN
JOIN
hive_subscriptions
hs
ON
hp
.
community_id
=
hs
.
community_id
JOIN
hive_accounts_view
ha
ON
ha
.
id
=
hp
.
author_id
WHERE
hs
.
account_id
=
__account_id
AND
hp
.
depth
=
0
AND
NOT
ha
.
is_grayed
AND
(
__post_id
=
0
OR
hp
.
id
<
__post_id
)
AND
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__account_id
AND
muted_id
=
hp
.
author_id
)
)
ORDER
BY
hp
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -117,7 +117,7 @@ BEGIN
JOIN
hive_subscriptions
hs
ON
hp
.
community_id
=
hs
.
community_id
WHERE
hs
.
account_id
=
__account_id
AND
NOT
hp
.
is_paidout
AND
hp
.
depth
=
0
AND
(
__post_id
=
0
OR
hp
.
sc_hot
<
__hot_limit
OR
(
hp
.
sc_hot
=
__hot_limit
AND
hp
.
id
<
__post_id
)
)
AND
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__account_id
AND
muted_id
=
hp
.
author_id
)
)
ORDER
BY
hp
.
sc_hot
DESC
,
hp
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -187,11 +187,11 @@ BEGIN
JOIN
hive_subscriptions
hs
ON
hp1
.
community_id
=
hs
.
community_id
WHERE
hs
.
account_id
=
__account_id
AND
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
depth
>
0
AND
(
__post_id
=
0
OR
(
hp1
.
payout
+
hp1
.
pending_payout
)
<
__payout_limit
OR
(
(
hp1
.
payout
+
hp1
.
pending_payout
)
=
__payout_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__account_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
(
hp1
.
payout
+
hp1
.
pending_payout
)
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
payout
JOIN
hive_posts_view
hp
ON
hp
.
id
=
payout
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
ORDER
BY
payout
.
all_payout
DESC
,
payout
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -258,7 +258,7 @@ BEGIN
JOIN
hive_subscriptions
hs
ON
hp
.
community_id
=
hs
.
community_id
WHERE
hs
.
account_id
=
__account_id
AND
NOT
hp
.
is_paidout
AND
hp
.
payout_at
BETWEEN
__head_block_time
+
interval
'12 hours'
AND
__head_block_time
+
interval
'36 hours'
AND
(
__post_id
=
0
OR
(
hp
.
payout
+
hp
.
pending_payout
)
<
__payout_limit
OR
(
(
hp
.
payout
+
hp
.
pending_payout
)
=
__payout_limit
AND
hp
.
id
<
__post_id
)
)
AND
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__account_id
AND
muted_id
=
hp
.
author_id
)
)
ORDER
BY
(
hp
.
payout
+
hp
.
pending_payout
)
DESC
,
hp
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -323,7 +323,7 @@ BEGIN
JOIN
hive_subscriptions
hs
ON
hp
.
community_id
=
hs
.
community_id
WHERE
hs
.
account_id
=
__account_id
AND
NOT
hp
.
is_paidout
AND
hp
.
promoted
>
0
AND
(
__post_id
=
0
OR
hp
.
promoted
<
__promoted_limit
OR
(
hp
.
promoted
=
__promoted_limit
AND
hp
.
id
<
__post_id
)
)
AND
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__account_id
AND
muted_id
=
hp
.
author_id
)
)
ORDER
BY
hp
.
promoted
DESC
,
hp
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -395,11 +395,11 @@ BEGIN
WHERE
hs
.
account_id
=
__account_id
AND
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
depth
=
0
AND
(
__post_id
=
0
OR
hp1
.
sc_trend
<
__trending_limit
OR
(
hp1
.
sc_trend
=
__trending_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__account_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
hp1
.
sc_trend
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
trending
JOIN
hive_posts_view
hp
ON
trending
.
id
=
hp
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
ORDER
BY
trending
.
sc_trend
DESC
,
trending
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -465,7 +465,6 @@ BEGIN
JOIN
hive_accounts_view
ha
ON
ha
.
id
=
hp
.
author_id
WHERE
hs
.
account_id
=
__account_id
AND
NOT
hp
.
is_paidout
AND
ha
.
is_grayed
AND
(
hp
.
payout
+
hp
.
pending_payout
)
>
0
AND
(
__post_id
=
0
OR
(
hp
.
payout
+
hp
.
pending_payout
)
<
__payout_limit
OR
(
(
hp
.
payout
+
hp
.
pending_payout
)
=
__payout_limit
AND
hp
.
id
<
__post_id
)
)
AND
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
True
END
)
ORDER
BY
(
hp
.
payout
+
hp
.
pending_payout
)
DESC
,
hp
.
id
DESC
LIMIT
_limit
;
END
...
...
hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql
View file @
934f2316
...
...
@@ -6,9 +6,11 @@ $function$
DECLARE
__post_id
INT
;
__hive_tag
INT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
__hive_tag
=
find_tag_id
(
_tag
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
RETURN
QUERY
SELECT
hp
.
id
,
hp
.
author
,
...
...
@@ -57,11 +59,11 @@ BEGIN
JOIN
hive_accounts_view
ha
ON
hp1
.
author_id
=
ha
.
id
WHERE
hpt
.
tag_id
=
__hive_tag
AND
hp1
.
counter_deleted
=
0
AND
hp1
.
depth
=
0
AND
NOT
ha
.
is_grayed
AND
(
__post_id
=
0
OR
hp1
.
id
<
__post_id
)
--ORDER BY hp1.id + 0 DESC -- this workaround helped the query to better choose indexes, but after some time it started to significally slow down
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
hp1
.
id
DESC
LIMIT
_limit
)
as
created
JOIN
hive_posts_view
hp
ON
hp
.
id
=
created
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
created
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -77,12 +79,14 @@ DECLARE
__post_id
INT
;
__hot_limit
FLOAT
;
__hive_tag
INT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
IF
__post_id
<>
0
THEN
SELECT
hp
.
sc_hot
INTO
__hot_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
__hive_tag
=
find_tag_id
(
_tag
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
RETURN
QUERY
SELECT
hp
.
id
,
hp
.
author
,
...
...
@@ -131,11 +135,11 @@ BEGIN
JOIN
hive_posts
hp1
ON
hp1
.
id
=
hpt
.
post_id
WHERE
hpt
.
tag_id
=
__hive_tag
AND
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
depth
=
0
AND
(
__post_id
=
0
OR
hp1
.
sc_hot
<
__hot_limit
OR
(
hp1
.
sc_hot
=
__hot_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
hp1
.
sc_hot
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
hot
JOIN
hive_posts_view
hp
ON
hp
.
id
=
hot
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
hot
.
hot
DESC
,
hot
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -210,7 +214,6 @@ BEGIN
LIMIT
_limit
)
as
payout
JOIN
hive_posts_view
hp
ON
hp
.
id
=
payout
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
payout
.
all_payout
DESC
,
payout
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -226,12 +229,14 @@ DECLARE
__post_id
INT
;
__payout_limit
hive_posts
.
payout
%
TYPE
;
__hive_category
INT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
IF
__post_id
<>
0
THEN
SELECT
(
hp
.
payout
+
hp
.
pending_payout
)
INTO
__payout_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
__hive_category
=
find_category_id
(
_category
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
RETURN
QUERY
SELECT
hp
.
id
,
hp
.
author
,
...
...
@@ -279,11 +284,11 @@ BEGIN
hive_posts
hp1
WHERE
hp1
.
category_id
=
__hive_category
AND
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
hp1
.
depth
>
0
AND
(
__post_id
=
0
OR
(
hp1
.
payout
+
hp1
.
pending_payout
)
<
__payout_limit
OR
(
(
hp1
.
payout
+
hp1
.
pending_payout
)
=
__payout_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
(
hp1
.
payout
+
hp1
.
pending_payout
)
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
payout
JOIN
hive_posts_view
hp
ON
hp
.
id
=
payout
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
payout
.
all_payout
DESC
,
payout
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -300,6 +305,7 @@ DECLARE
__payout_limit
hive_posts
.
payout
%
TYPE
;
__head_block_time
TIMESTAMP
;
__hive_category
INT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
IF
__post_id
<>
0
THEN
...
...
@@ -307,6 +313,7 @@ BEGIN
END
IF
;
__hive_category
=
find_category_id
(
_category
,
True
);
__head_block_time
=
head_block_time
();
__observer_id
=
find_account_id
(
_observer
,
False
);
RETURN
QUERY
SELECT
hp
.
id
,
hp
.
author
,
...
...
@@ -355,11 +362,11 @@ BEGIN
WHERE
hp1
.
category_id
=
__hive_category
AND
hp1
.
counter_deleted
=
0
AND
NOT
hp1
.
is_paidout
AND
(
(
NOT
_bridge_api
AND
hp1
.
depth
=
0
)
OR
(
_bridge_api
AND
hp1
.
payout_at
BETWEEN
__head_block_time
+
interval
'12 hours'
AND
__head_block_time
+
interval
'36 hours'
)
)
AND
(
__post_id
=
0
OR
(
hp1
.
payout
+
hp1
.
pending_payout
)
<
__payout_limit
OR
(
(
hp1
.
payout
+
hp1
.
pending_payout
)
=
__payout_limit
AND
hp1
.
id
<
__post_id
)
)
AND
(
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_by_id_view
WHERE
observer_id
=
__observer_id
AND
muted_id
=
hp1
.
author_id
))
ORDER
BY
(
hp1
.
payout
+
hp1
.
pending_payout
)
DESC
,
hp1
.
id
DESC
LIMIT
_limit
)
as
payout
JOIN
hive_posts_view
hp
ON
hp
.
id
=
payout
.
id
WHERE
(
CASE
WHEN
_observer
IS
NOT
NULL
THEN
NOT
EXISTS
(
SELECT
1
FROM
muted_accounts_view
WHERE
observer
=
_observer
AND
muted
=
hp
.
author
)
ELSE
true
END
)
ORDER
BY
payout
.
all_payout
DESC
,
payout
.
id
DESC
LIMIT
_limit
;
END
...
...
@@ -375,12 +382,14 @@ DECLARE
__post_id
INT
;
__promoted_limit
hive_posts
.
promoted
%
TYPE
;
__hive_tag
INT
;
__observer_id
INT
;
BEGIN
__post_id
=
find_comment_id
(
_author
,
_permlink
,
True
);
IF
__post_id
<>
0
THEN
SELECT
hp
.
promoted
INTO
__promoted_limit
FROM
hive_posts
hp
WHERE
hp
.
id
=
__post_id
;
END
IF
;
__hive_tag
=
find_tag_id
(
_tag
,
True
);
__observer_id
=
find_account_id
(
_observer
,
False
);
RETURN
QUERY
SELECT
hp
.
id
,
hp
.
author
,
...
...
@@ -429,11 +438,11 @@ BEGIN
JOIN
hive_posts
hp1
ON
hp1
.
id
=
hpt
.
post_id
WHERE
hpt
.
tag_id
=
__hive_tag
AND
hp1
.
counter_deleted
=