Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hive/hivemind
1 result
Show changes
Commits on Source (21)
Showing
with 58 additions and 123 deletions
......@@ -601,7 +601,6 @@ def setup(db):
"database_api_list_votes.sql",
"update_posts_rshares.sql",
"update_hive_post_root_id.sql",
"condenser_get_by_replies_to_account.sql",
"condenser_get_by_account_comments.sql",
"condenser_get_by_blog_without_reblog.sql",
"bridge_get_by_feed_with_reblog.sql",
......
DROP FUNCTION IF EXISTS bridge_get_account_posts_by_replies;
CREATE FUNCTION bridge_get_account_posts_by_replies( in _account VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT )
CREATE FUNCTION bridge_get_account_posts_by_replies( in _account VARCHAR, in _author VARCHAR, in _permlink VARCHAR, in _limit SMALLINT, in _bridge_api BOOLEAN )
RETURNS SETOF bridge_api_post
AS
$function$
......@@ -8,8 +8,18 @@ DECLARE
__account_id INT;
__post_id INT;
BEGIN
__account_id = find_account_id( _account, True );
__post_id = find_comment_id( _author, _permlink, True );
IF NOT _bridge_api AND _permlink <> '' THEN
-- find blogger account using parent author of page defining post
__post_id = find_comment_id( _author, _permlink, True );
SELECT pp.author_id INTO __account_id
FROM hive_posts hp
JOIN hive_posts pp ON hp.parent_id = pp.id
WHERE hp.id = __post_id;
IF __account_id = 0 THEN __account_id = NULL; END IF;
ELSE
__account_id = find_account_id( _account, True );
__post_id = find_comment_id( _author, _permlink, True );
END IF;
RETURN QUERY SELECT
hp.id,
hp.author,
......
......@@ -2,7 +2,8 @@ DROP FUNCTION IF EXISTS get_discussion
;
CREATE OR REPLACE FUNCTION get_discussion(
in _author hive_accounts.name%TYPE,
in _permlink hive_permlink_data.permlink%TYPE
in _permlink hive_permlink_data.permlink%TYPE,
in _observer VARCHAR
)
RETURNS TABLE
(
......@@ -72,12 +73,13 @@ BEGIN
SELECT hp.id, hp.parent_id
FROM hive_posts hp
WHERE hp.id = __post_id
AND NOT hp.is_muted
UNION ALL
SELECT children.id, children.parent_id
FROM hive_posts children
JOIN child_posts ON children.parent_id = child_posts.id
WHERE children.counter_deleted = 0 AND NOT children.is_muted
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)
)
SELECT hp2.id
FROM hive_posts hp2
......
......@@ -27,7 +27,7 @@ BEGIN
__account_id = find_account_id( _account, True );
__start_id = find_account_id( _start, _start <> '' );
IF __start_id <> 0 THEN
SELECT INTO __start_id COALESCE( ( SELECT id FROM hive_follows WHERE following = __account_id AND follower = __start_id ), 0 );
SELECT INTO __start_id ( SELECT id FROM hive_follows WHERE following = __account_id AND follower = __start_id );
END IF;
RETURN QUERY SELECT
ha.name
......@@ -55,7 +55,7 @@ BEGIN
__account_id = find_account_id( _account, True );
__start_id = find_account_id( _start, _start <> '' );
IF __start_id <> 0 THEN
SELECT INTO __start_id COALESCE( ( SELECT id FROM hive_follows WHERE follower = __account_id AND following = __start_id ), 0 );
SELECT INTO __start_id ( SELECT id FROM hive_follows WHERE follower = __account_id AND following = __start_id );
END IF;
RETURN QUERY SELECT
ha.name
......
DROP FUNCTION IF EXISTS condenser_get_by_replies_to_account;
CREATE OR REPLACE FUNCTION condenser_get_by_replies_to_account(
in _author VARCHAR,
in _permlink VARCHAR,
in _limit INTEGER
)
RETURNS SETOF bridge_api_post
AS
$function$
DECLARE
__post_id INTEGER := 0;
BEGIN
IF _permlink <> '' THEN
SELECT
ha_pp.name, hp.id
INTO
_author, __post_id
FROM hive_posts hp
JOIN hive_posts pp ON hp.parent_id = pp.id
JOIN hive_accounts ha_pp ON ha_pp.id = pp.author_id
JOIN hive_permlink_data hpd_pp ON hpd_pp.id = pp.permlink_id
JOIN hive_accounts ha ON hp.author_id = ha.id
WHERE
hpd_pp.permlink = _permlink AND ha.name = _author;
END IF;
RETURN QUERY SELECT
hp.id,
hp.author,
hp.parent_author,
hp.author_rep,
hp.root_title,
hp.beneficiaries,
hp.max_accepted_payout,
hp.percent_hbd,
hp.url,
hp.permlink,
hp.parent_permlink_or_category,
hp.title,
hp.body,
hp.category,
hp.depth,
hp.promoted,
hp.payout,
hp.pending_payout,
hp.payout_at,
hp.is_paidout,
hp.children,
hp.votes,
hp.created_at,
hp.updated_at,
hp.rshares,
hp.abs_rshares,
hp.json,
hp.is_hidden,
hp.is_grayed,
hp.total_votes,
hp.sc_trend,
hp.role_title,
hp.community_title,
hp.role_id,
hp.is_pinned,
hp.curator_payout_value,
hp.is_muted
FROM hive_posts_view hp
JOIN
(
SELECT hp.id
FROM hive_posts_view hp
WHERE hp.author = _author
ORDER BY hp.id DESC
LIMIT _limit
) T ON hp.parent_id = T.id
WHERE ( ( __post_id = 0 ) OR ( hp.id <= __post_id ) )
ORDER BY hp.id DESC
LIMIT _limit;
END
$function$
language plpgsql STABLE;
......@@ -52,7 +52,6 @@ for sql in postgres_handle_view_changes.sql \
database_api_list_votes.sql \
update_posts_rshares.sql \
update_hive_post_root_id.sql \
condenser_get_by_replies_to_account.sql \
condenser_get_by_account_comments.sql \
condenser_get_by_blog_without_reblog.sql \
bridge_get_by_feed_with_reblog.sql \
......
......@@ -25,7 +25,7 @@ FROM
, rank() OVER(order by ha3.reputation DESC) as rank
FROM hive_accounts ha3
ORDER BY ha3.reputation DESC LIMIT 150000
-- Conditions above (related to rank.position) eliminates all records having rank > 100k. So with inclding some
-- Conditions above (related to rank.position) eliminates all records having rank > 100k. So with inclding some
-- additional space for redundant accounts (having same reputation) lets assume we're limiting it to 150k
-- As another reason, it can be pointed that only 2% of account has the same reputations, it means only 2000
-- in 100000, but we get 150000 as 50% would repeat
......@@ -130,7 +130,7 @@ UNION ALL
''::character varying(16) AS community,
''::character varying AS community_title,
''::character varying AS payload
FROM hive_follows hf
FROM hive_follows hf WHERE hf.state = 1 --only follow blog
UNION ALL
SELECT hr.block_num,
notification_id(hr.block_num, 14, hr.id) AS id,
......
......@@ -166,6 +166,7 @@ values
,(now(), '1f23e1326f3010bc84353aba82d4aa7ff2f999e4') -- hive_posts_author_id_created_at_idx index def. to speedup hive_accounts_info_view.
,(now(), '2a274e586454968a4f298a855a7e60394ed90bde') -- get_number_of_unread_notifications speedup https://gitlab.syncad.com/hive/hivemind/-/merge_requests/348/diffs
,(now(), '431fdaead7dcd69e4d2a45e7ce8a3186b8075515') -- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/367
,(now(), 'cc7bb174d40fe1a0e2221d5d7e1c332c344dca34') -- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/372
) ds (patch_date, patch_revision)
where not exists (select null from hive_db_patch_level hpl where hpl.patched_to_revision = ds.patch_revision);
......
......@@ -302,6 +302,12 @@ select 'update_hive_posts_children_count execution'
where not exists (select null from hive_db_patch_level where patched_to_revision = '0e3c8700659d98b45f1f7146dc46a195f905fc2d' )
;
-- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/372
INSERT INTO hive_db_data_migration
select 'Notification cache initial fill'
where not exists (select null from hive_db_patch_level where patched_to_revision = 'cc7bb174d40fe1a0e2221d5d7e1c332c344dca34' )
;
--- 1847c75702384c7e34c624fc91f24d2ef20df91d latest version of develop included in this migration script.
--- Rename hive_votes_ux1 unique constraint to the hive_votes_voter_id_author_id_permlink_id_uk
......@@ -322,12 +328,6 @@ CREATE INDEX IF NOT EXISTS hive_posts_author_id_created_at_idx ON public.hive_po
CREATE INDEX IF NOT EXISTS hive_blocks_created_at_idx ON hive_blocks (created_at);
INSERT INTO hive_db_data_migration
SELECT 'Notification cache initial fill'
WHERE NOT EXISTS (SELECT data_type
FROM information_schema.columns
WHERE table_name = 'hive_notification_cache');
--- Notification cache to significantly speedup notification APIs.
CREATE TABLE IF NOT EXISTS hive_notification_cache
(
......
......@@ -289,7 +289,7 @@ async def get_account_posts(context, sort:str, account:str, start_author:str='',
sql = "SELECT * FROM bridge_get_account_posts_by_comments( (:account)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
elif sort == 'replies':
account_posts = False
sql = "SELECT * FROM bridge_get_account_posts_by_replies( (:account)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_account_posts_by_replies( (:account)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, True )"
elif sort == 'payout':
sql = "SELECT * FROM bridge_get_account_posts_by_payout( (:account)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
......
......@@ -26,8 +26,8 @@ async def get_discussion(context, author, permlink, observer=None):
if observer:
blacklists_for_user = await Mutes.get_blacklists_for_observer(observer, context)
sql = "SELECT * FROM get_discussion(:author,:permlink)"
rows = await db.query_all(sql, author=author, permlink=permlink)
sql = "SELECT * FROM get_discussion(:author,:permlink,:observer)"
rows = await db.query_all(sql, author=author, permlink=permlink, observer=observer)
if not rows or len(rows) == 0:
return {}
root_id = rows[0]['id']
......
......@@ -21,18 +21,16 @@ async def get_following(db, account: str, start: str, state: int, limit: int):
async def get_reblogged_by(db, author: str, permlink: str):
"""Return all rebloggers of a post."""
sql = "SELECT * FROM condenser_get_names_by_reblogged( '{}', '{}' )".format( author, permlink )
names = await db.query_col(sql)
sql = "SELECT * FROM condenser_get_names_by_reblogged( (:author)::VARCHAR, (:permlink)::VARCHAR )"
names = await db.query_col(sql, author=author, permlink=permlink)
if author in names:
names.remove(author)
return names
async def get_data(db, sql:str, truncate_body: int = 0):
result = await db.query_all(sql);
async def process_posts(db, sql_result, truncate_body: int = 0):
posts = []
for row in result:
for row in sql_result:
row = dict(row)
post = _condenser_post_object(row, truncate_body=truncate_body)
......@@ -43,20 +41,24 @@ async def get_data(db, sql:str, truncate_body: int = 0):
async def get_by_blog_without_reblog(db, account: str, start_permlink: str = '', limit: int = 20, truncate_body: int = 0):
"""Get a list of posts for an author's blog without reblogs."""
sql = " SELECT * FROM condenser_get_by_blog_without_reblog( '{}', '{}', {} ) ".format( account, start_permlink, limit )
return await get_data(db, sql, truncate_body )
sql = "SELECT * FROM condenser_get_by_blog_without_reblog( (:author)::VARCHAR, (:permlink)::VARCHAR, :limit )"
result = await db.query_all(sql, author=account, permlink=start_permlink, limit=limit);
return await process_posts(db, result, truncate_body)
async def get_by_account_comments(db, account: str, start_permlink: str = '', limit: int = 20, truncate_body: int = 0):
"""Get a list of posts representing comments by an author."""
sql = " SELECT * FROM condenser_get_by_account_comments( '{}', '{}', {} ) ".format( account, start_permlink, limit )
return await get_data(db, sql, truncate_body )
sql = "SELECT * FROM condenser_get_by_account_comments( (:author)::VARCHAR, (:permlink)::VARCHAR, :limit )"
result = await db.query_all(sql, author=account, permlink=start_permlink, limit=limit);
return await process_posts(db, result, truncate_body)
async def get_by_replies_to_account(db, start_author: str, start_permlink: str = '', limit: int = 20, truncate_body: int = 0):
"""Get a list of posts representing replies to an author."""
sql = " SELECT * FROM condenser_get_by_replies_to_account( '{}', '{}', {} ) ".format( start_author, start_permlink, limit )
return await get_data(db, sql, truncate_body )
sql = "SELECT * FROM bridge_get_account_posts_by_replies( (:account)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, False )"
result = await db.query_all(sql, account=start_author, author=start_author if start_permlink else '', permlink=start_permlink, limit=limit);
return await process_posts(db, result, truncate_body)
async def get_by_blog(db, account: str = '', start_author: str = '', start_permlink: str = '', limit: int = 20):
"""Get a list of posts for an author's blog."""
sql = " SELECT * FROM condenser_get_by_blog( '{}', '{}', '{}', {} ) ".format( account, start_author, start_permlink, limit )
return await get_data(db, sql )
sql = "SELECT * FROM condenser_get_by_blog( (:account)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, :limit )"
result = await db.query_all(sql, account=account, author=start_author, permlink=start_permlink, limit=limit);
return await process_posts(db, result)
......@@ -234,11 +234,11 @@ async def _child_ids(db, parent_ids):
rows = await db.query_all(sql, ids=tuple(parent_ids))
return [[row[0], row[1]] for row in rows]
async def _load_discussion(db, author, permlink):
async def _load_discussion(db, author, permlink, observer=None):
"""Load a full discussion thread."""
sql = "SELECT * FROM get_discussion('{}','{}')".format( author, permlink)
sql_result = await db.query_all(sql)
sql = "SELECT * FROM get_discussion(:author,:permlink,:observer)"
sql_result = await db.query_all(sql, author=author, permlink=permlink, observer=observer)
muted_accounts = Mutes.all()
posts = []
......
......@@ -379,8 +379,12 @@ async def get_discussions_by_comments(context, start_author: str = None, start_p
async def get_replies_by_last_update(context, start_author: str = None, start_permlink: str = '',
limit: int = 20, truncate_body: int = 0):
"""Get all replies made to any of author's posts."""
assert start_author, '`start_author` cannot be blank'
# despite the name time of last edit is not used, posts ranked by creation time (that is, their id)
# note that in this call start_author has dual meaning:
# - when there is only start_author it means account that authored posts that we seek replies to
# - when there is also start_permlink it points to one of replies (last post of previous page) and
# we'll be getting account like above in form of author of parent post to the post pointed by
# given start_author+start_permlink
return await cursor.get_by_replies_to_account(
context['db'],
valid_account(start_author),
......
Subproject commit cbb2c1c95d56181310e25d2ddcb9baff1bdaa83f
Subproject commit c9a3f6ecc01e3bed1098bf9698e95002ccdd47d6