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
Showing
with 185 additions and 140 deletions
DROP VIEW IF EXISTS muted_accounts_view;
CREATE OR REPLACE VIEW muted_accounts_view AS
(
SELECT observer_accounts.name AS observer, following_accounts.name AS muted
FROM hive_follows JOIN hive_accounts following_accounts ON hive_follows.following = following_accounts.id
JOIN hive_accounts observer_accounts ON hive_follows.follower = observer_accounts.id
WHERE hive_follows.state = 2
UNION
SELECT observer_accounts.name AS observer, following_accounts.name AS muted
FROM hive_follows hive_follows_direct JOIN hive_follows hive_follows_indirect ON hive_follows_direct.following = hive_follows_indirect.follower
JOIN hive_accounts following_accounts ON hive_follows_indirect.following = following_accounts.id
JOIN hive_accounts observer_accounts ON hive_follows_direct.follower = observer_accounts.id
WHERE hive_follows_direct.follow_muted AND hive_follows_indirect.state = 2
);
\ No newline at end of file
......@@ -32,22 +32,8 @@ SELECT hp.id,
hp.updated_at,
hp.vote_rshares AS rshares,
hp.abs_rshares AS abs_rshares,
COALESCE(
(
SELECT COUNT( 1 )
FROM hive_votes v
WHERE v.post_id = hp.id AND v.is_effective
GROUP BY v.post_id
), 0
) AS total_votes,
COALESCE(
(
SELECT SUM( CASE v.rshares > 0 WHEN True THEN 1 ELSE -1 END )
FROM hive_votes v
WHERE v.post_id = hp.id AND NOT v.rshares = 0
GROUP BY v.post_id
), 0
) AS net_votes,
hp.total_votes AS total_votes,
hp.net_votes as net_votes,
hpd.json,
ha_a.reputation AS author_rep,
hp.is_hidden,
......
......@@ -17,12 +17,20 @@ SET
, vote_rshares = votes_rshares.rshares
, sc_hot = CASE hp.is_paidout WHEN True Then 0 ELSE calculate_hot( votes_rshares.rshares, hp.created_at) END
, sc_trend = CASE hp.is_paidout WHEN True Then 0 ELSE calculate_tranding( votes_rshares.rshares, hp.created_at) END
, total_votes = votes_rshares.total_votes
, net_votes = votes_rshares.net_votes
FROM
(
SELECT
hv.post_id
, SUM( hv.rshares ) as rshares
, SUM( ABS( hv.rshares ) ) as abs_rshares
, SUM( CASE hv.is_effective WHEN True THEN 1 ELSE 0 END ) as total_votes
, SUM( CASE
WHEN hv.rshares > 0 THEN 1
WHEN hv.rshares = 0 THEN 0
ELSE -1
END ) as net_votes
FROM hive_votes hv
WHERE EXISTS
(
......@@ -33,7 +41,12 @@ FROM
GROUP BY hv.post_id
) as votes_rshares
WHERE hp.id = votes_rshares.post_id
AND (hp.abs_rshares != votes_rshares.abs_rshares OR hp.vote_rshares != votes_rshares.rshares);
AND (
hp.abs_rshares != votes_rshares.abs_rshares
OR hp.vote_rshares != votes_rshares.rshares
OR hp.total_votes != votes_rshares.total_votes
OR hp.net_votes != votes_rshares.net_votes
);
RESET work_mem;
RESET enable_seqscan;
END;
......
......@@ -132,7 +132,7 @@ TRUNCATE TABLE hive_db_data_migration;
insert into hive_db_patch_level
(patch_date, patched_to_revision)
select ds.patch_date, ds.patch_revision
from
from
(
values
(now(), '7b8def051be224a5ebc360465f7a1522090c7125'),
......@@ -146,7 +146,7 @@ values
-- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/257
-- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/251
-- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/265
--
--
(now(), '45c2883131472cc14a03fe4e355ba1435020d720'),
(now(), '7cfc2b90a01b32688075b22a6ab173f210fc770f'), -- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/286
(now(), 'f2e5f656a421eb1dd71328a94a421934eda27a87') -- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/275
......@@ -165,10 +165,10 @@ values
,(now(), '1847c75702384c7e34c624fc91f24d2ef20df91d') -- latest version of develop containing included changes.
,(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
) ds (patch_date, patch_revision)
where not exists (select null from hive_db_patch_level hpl where hpl.patched_to_revision = ds.patch_revision);
COMMIT;
;
......@@ -15,7 +15,7 @@ BEGIN
EXECUTE 'ALTER DATABASE '||current_database()||' SET join_collapse_limit TO 16';
EXECUTE 'ALTER DATABASE '||current_database()||' SET from_collapse_limit TO 16';
END
$$;
$$;
SHOW join_collapse_limit;
SHOW from_collapse_limit;
......@@ -31,13 +31,13 @@ IF NOT EXISTS(SELECT data_type
alter table ONlY hive_accounts
add column is_implicit boolean,
alter column is_implicit set default True;
--- reputations have to be recalculated from scratch.
update hive_accounts set reputation = 0, is_implicit = True;
alter table ONlY hive_accounts
alter column is_implicit set not null;
perform deps_restore_dependencies('public', 'hive_accounts');
INSERT INTO hive_db_data_migration VALUES ('Reputation calculation');
......@@ -187,7 +187,34 @@ IF EXISTS(SELECT data_type FROM information_schema.columns
ELSE
RAISE NOTICE 'SKIPPING hive_posts upgrade - adding a block_num_created column, type change for abs_rshares/vote_rshares columns';
END IF;
--- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/367
IF NOT EXISTS (SELECT data_type FROM information_schema.columns
WHERE table_name = 'hive_posts' AND column_name = 'total_votes')
AND NOT EXISTS (SELECT data_type FROM information_schema.columns
WHERE table_name = 'hive_posts' AND column_name = 'net_votes') THEN
RAISE NOTICE 'Performing hive_posts upgrade - adding total_votes and net_votes columns';
PERFORM deps_save_and_drop_dependencies('public', 'hive_posts', true);
ALTER TABLE ONLY hive_posts
ADD COLUMN total_votes BIGINT,
ADD COLUMN net_votes BIGINT;
UPDATE hive_posts SET total_votes = 0, net_votes = 0; -- Artificial number, requires to start update_posts_rshares for all blocks
ALTER TABLE ONLY hive_posts
ALTER COLUMN total_votes SET NOT NULL,
ALTER COLUMN total_votes SET DEFAULT 0,
ALTER COLUMN net_votes SET NOT NULL,
ALTER COLUMN net_votes SET DEFAULT 0;
PERFORM deps_restore_dependencies('public', 'hive_posts');
ELSE
RAISE NOTICE 'SKIPPING hive_posts upgrade - adding total_votes and net_votes columns';
END IF;
END
$BODY$
;
......@@ -200,9 +227,9 @@ DROP INDEX IF EXISTS hive_mentions_post_id_idx;
-- updated up to 7b8def051be224a5ebc360465f7a1522090c7125
-- updated up to 033619277eccea70118a5b8dc0c73b913da0025f
INSERT INTO hive_db_data_migration
INSERT INTO hive_db_data_migration
select 'update_posts_rshares( 0, head_block_number) execution'
where not exists (select null from hive_db_patch_level where patched_to_revision = '033619277eccea70118a5b8dc0c73b913da0025f')
where not exists (select null from hive_db_patch_level where patched_to_revision = '431fdaead7dcd69e4d2a45e7ce8a3186b8075515')
;
-- updated to e8b65adf22654203f5a79937ff2a95c5c47e10c5 - See merge request hive/hivemind!251
......@@ -228,13 +255,13 @@ IF NOT EXISTS(SELECT data_type
alter table ONLY hive_follows
add column follow_muted boolean,
alter column follow_muted set default False;
--- Fill the default value for all existing records.
update hive_follows set follow_muted = False;
alter table ONlY hive_follows
alter column follow_muted set not null;
perform deps_restore_dependencies('public', 'hive_follows');
ELSE
RAISE NOTICE 'hive_follows::follow_muted migration skipped';
......@@ -245,7 +272,7 @@ $BODY$;
--- 4cdf5d19f6cfcb73d3fa504cac9467c4df31c02e - https://gitlab.syncad.com/hive/hivemind/-/merge_requests/295
--- 9e126e9d762755f2b9a0fd68f076c9af6bb73b76 - https://gitlab.syncad.com/hive/hivemind/-/merge_requests/314 mentions fix
INSERT INTO hive_db_data_migration
INSERT INTO hive_db_data_migration
select 'update_hive_post_mentions refill execution'
where not exists (select null from hive_db_patch_level where patched_to_revision = '9e126e9d762755f2b9a0fd68f076c9af6bb73b76' )
;
......@@ -270,7 +297,7 @@ CREATE INDEX IF NOT EXISTS hive_votes_voter_id_last_update_idx ON hive_votes (vo
--- https://gitlab.syncad.com/hive/hivemind/-/merge_requests/306 update posts children count fix
--- 0e3c8700659d98b45f1f7146dc46a195f905fc2d
INSERT INTO hive_db_data_migration
INSERT INTO hive_db_data_migration
select 'update_hive_posts_children_count execution'
where not exists (select null from hive_db_patch_level where patched_to_revision = '0e3c8700659d98b45f1f7146dc46a195f905fc2d' )
;
......@@ -356,4 +383,3 @@ DROP INDEX IF EXISTS hive_posts_promoted_idx;
CREATE INDEX IF NOT EXISTS hive_posts_promoted_id_idx ON hive_posts (promoted, id)
WHERE NOT is_paidout AND counter_deleted = 0
;
......@@ -103,20 +103,20 @@ async def _get_ranked_posts_for_observer_communities( db, sort:str, start_author
assert False, "Unknown sort order"
@return_error_info
async def _get_ranked_posts_for_communities( db, sort:str, community, start_author:str, start_permlink:str, limit):
async def _get_ranked_posts_for_communities( db, sort:str, community, start_author:str, start_permlink:str, limit, observer:str=None):
async def execute_community_query(db, sql, limit):
return await db.query_all(sql, community=community, author=start_author, permlink=start_permlink, limit=limit )
return await db.query_all(sql, community=community, author=start_author, permlink=start_permlink, limit=limit, observer=observer )
pinned_sql = "SELECT * FROM bridge_get_ranked_post_pinned_for_community( (:community)::VARCHAR, (:limit)::SMALLINT )"
pinned_sql = "SELECT * FROM bridge_get_ranked_post_pinned_for_community( (:community)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
# missing paging which results in inability to get all pinned posts
# and/or causes the same posts to be on each page (depending on limit and number of pinned)
if sort == 'hot':
sql = "SELECT * FROM bridge_get_ranked_post_by_hot_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_hot_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_community_query(db, sql, limit)
if sort == 'trending':
result_with_pinned_posts = []
sql = "SELECT * FROM bridge_get_ranked_post_by_trends_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, True )"
sql = "SELECT * FROM bridge_get_ranked_post_by_trends_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, True, (:observer)::VARCHAR )"
result_with_pinned_posts = await execute_community_query(db, pinned_sql, limit)
limit -= len(result_with_pinned_posts)
if limit > 0:
......@@ -124,11 +124,11 @@ async def _get_ranked_posts_for_communities( db, sort:str, community, start_auth
return result_with_pinned_posts
if sort == 'promoted':
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_community_query(db, sql, limit)
if sort == 'created':
sql = "SELECT * FROM bridge_get_ranked_post_by_created_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, True )"
sql = "SELECT * FROM bridge_get_ranked_post_by_created_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, True, (:observer)::VARCHAR )"
result_with_pinned_posts = await execute_community_query(db, pinned_sql, limit)
limit -= len(result_with_pinned_posts)
if limit > 0:
......@@ -136,86 +136,86 @@ async def _get_ranked_posts_for_communities( db, sort:str, community, start_auth
return result_with_pinned_posts
if sort == 'muted':
sql = "SELECT * FROM bridge_get_ranked_post_by_muted_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_muted_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_community_query(db, sql, limit)
if sort == 'payout':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_community_query(db, sql, limit)
if sort == 'payout_comments':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments_for_community( (:community)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_community_query(db, sql, limit)
assert False, "Unknown sort order"
@return_error_info
async def _get_ranked_posts_for_tag( db, sort:str, tag, start_author:str, start_permlink:str, limit):
async def _get_ranked_posts_for_tag( db, sort:str, tag, start_author:str, start_permlink:str, limit, observer:str=None):
async def execute_tags_query(db, sql, limit):
return await db.query_all(sql, tag=tag, author=start_author, permlink=start_permlink, limit=limit )
return await db.query_all(sql, tag=tag, author=start_author, permlink=start_permlink, limit=limit, observer=observer )
if sort == 'hot':
sql = "SELECT * FROM bridge_get_ranked_post_by_hot_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_hot_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
if sort == 'promoted':
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
if sort == 'payout':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_for_category( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, True )"
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_for_category( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, True, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
if sort == 'payout_comments':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments_for_category( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments_for_category( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
if sort == 'muted':
sql = "SELECT * FROM bridge_get_ranked_post_by_muted_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_muted_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
if sort == 'trending':
sql = "SELECT * FROM bridge_get_ranked_post_by_trends_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_trends_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
if sort == 'created':
sql = "SELECT * FROM bridge_get_ranked_post_by_created_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_created_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_tags_query(db, sql, limit)
assert False, "Unknown sort order"
@return_error_info
async def _get_ranked_posts_for_all( db, sort:str, start_author:str, start_permlink:str, limit):
async def execute_query(db, sql, limit):
return await db.query_all(sql, author=start_author, permlink=start_permlink, limit=limit )
async def _get_ranked_posts_for_all( db, sort:str, start_author:str, start_permlink:str, limit, observer:str=None):
async def execute_query(db, sql, limit, observer=None):
return await db.query_all(sql, author=start_author, permlink=start_permlink, limit=limit, observer=observer )
if sort == 'trending':
sql = "SELECT * FROM bridge_get_ranked_post_by_trends( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_trends( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
if sort == 'created':
sql = "SELECT * FROM bridge_get_ranked_post_by_created( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
return await execute_query(db, sql, limit)
sql = "SELECT * FROM bridge_get_ranked_post_by_created( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit, observer)
if sort == 'hot':
sql = "SELECT * FROM bridge_get_ranked_post_by_hot( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_hot( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
if sort == 'promoted':
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
if sort == 'payout':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, True )"
sql = "SELECT * FROM bridge_get_ranked_post_by_payout( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, True, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
if sort == 'payout_comments':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
if sort == 'muted':
sql = "SELECT * FROM bridge_get_ranked_post_by_muted( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_muted( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
return await execute_query(db, sql, limit)
assert False, "Unknown sort order"
......@@ -252,14 +252,14 @@ async def get_ranked_posts(context, sort:str, start_author:str='', start_permlin
return await process_query_results(result)
if tag and tag[:5] == 'hive-':
result = await _get_ranked_posts_for_communities(db, sort, tag, start_author, start_permlink, limit)
result = await _get_ranked_posts_for_communities(db, sort, tag, start_author, start_permlink, limit, observer)
return await process_query_results(result)
if ( tag and tag != "all" ):
result = await _get_ranked_posts_for_tag(db, sort, tag, start_author, start_permlink, limit)
result = await _get_ranked_posts_for_tag(db, sort, tag, start_author, start_permlink, limit, observer)
return await process_query_results(result)
result = await _get_ranked_posts_for_all(db, sort, start_author, start_permlink, limit)
result = await _get_ranked_posts_for_all(db, sort, start_author, start_permlink, limit, observer)
return await process_query_results(result)
@return_error_info
......
......@@ -15,21 +15,19 @@ log = logging.getLogger(__name__)
# pylint: disable=too-many-lines
def append_statistics_to_post(post, row, is_pinned, blacklists_for_user=None, override_gray=False):
def append_statistics_to_post(post, row, is_pinned, blacklists_for_user=[], override_gray=False):
""" apply information such as blacklists and community names/roles to a given post """
if not blacklists_for_user:
post['blacklists'] = Mutes.lists(row['author'], row['author_rep'])
else:
post['blacklists'] = []
if row['author'] in blacklists_for_user:
blacklists = blacklists_for_user[row['author']]
for blacklist in blacklists:
post['blacklists'].append(blacklist)
reputation = row['author_rep']
if reputation < 1:
post['blacklists'].append('reputation-0')
elif reputation == 1:
post['blacklists'].append('reputation-1')
post['blacklists'] = []
if blacklists_for_user and row['author'] in blacklists_for_user:
blacklists = blacklists_for_user[row['author']]
for blacklist in blacklists:
post['blacklists'].append(blacklist)
reputation = row['author_rep']
if reputation < 1:
post['blacklists'].append('reputation-0')
elif reputation == 1:
post['blacklists'].append('reputation-1')
if 'community_title' in row and row['community_title']:
post['community'] = row['category']
......@@ -40,13 +38,10 @@ def append_statistics_to_post(post, row, is_pinned, blacklists_for_user=None, ov
else:
post['author_role'] = 'guest'
post['author_title'] = ''
elif override_gray:
post['stats']['gray'] = ('irredeemables' in post['blacklists'] or len(post['blacklists']) >= 2)
else:
post['stats']['gray'] = row['is_grayed']
post['stats']['hide'] = 'irredeemables' in post['blacklists']
# it overrides 'is_hidden' flag from post, is that the intent?
post['stats']['gray'] = row['is_grayed']
if 'is_muted' in row and row['is_muted']:
post['stats']['gray'] = True
if is_pinned:
post['stats']['is_pinned'] = True
return post
......
......@@ -174,7 +174,7 @@ def nested_query_compat(function):
@nested_query_compat
async def get_posts_by_given_sort(context, sort: str, start_author: str = '', start_permlink: str = '',
limit: int = 20, tag: str = None,
truncate_body: int = 0, filter_tags: list = None):
truncate_body: int = 0, filter_tags: list = None, observer:str=None):
"""Query posts, sorted by creation date."""
assert not filter_tags, 'filter_tags not supported'
......@@ -184,52 +184,53 @@ async def get_posts_by_given_sort(context, sort: str, start_author: str = '', st
start_permlink = valid_permlink(start_permlink, allow_empty=True),
limit = valid_limit(limit, 100, 20),
tag = valid_tag(tag, allow_empty=True)
observer = valid_account(observer, allow_empty=True)
posts = []
is_community = tag[:5] == 'hive-'
if sort == 'created':
if is_community:
sql = "SELECT * FROM bridge_get_ranked_post_by_created_for_community( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, False )"
sql = "SELECT * FROM bridge_get_ranked_post_by_created_for_community( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, False, (:observer)::VARCHAR )"
elif tag == '':
sql = "SELECT * FROM bridge_get_ranked_post_by_created( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_created( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
else:
sql = "SELECT * FROM bridge_get_ranked_post_by_created_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_created_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
elif sort == 'trending':
if is_community:
sql = "SELECT * FROM bridge_get_ranked_post_by_trends_for_community( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, False )"
sql = "SELECT * FROM bridge_get_ranked_post_by_trends_for_community( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, False, (:observer)::VARCHAR )"
elif tag == '':
sql = "SELECT * FROM bridge_get_ranked_post_by_trends( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_trends( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
else:
sql = "SELECT * FROM bridge_get_ranked_post_by_trends_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_trends_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
elif sort == 'hot':
if is_community:
sql = "SELECT * FROM bridge_get_ranked_post_by_hot_for_community( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_hot_for_community( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
elif tag == '':
sql = "SELECT * FROM bridge_get_ranked_post_by_hot( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_hot( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
else:
sql = "SELECT * FROM bridge_get_ranked_post_by_hot_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_hot_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
elif sort == 'promoted':
if is_community:
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted_for_community( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted_for_community( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
elif tag == '':
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
else:
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_promoted_for_tag( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
elif sort == 'post_by_payout':
if tag == '':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, False )"
sql = "SELECT * FROM bridge_get_ranked_post_by_payout( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, False, (:observer)::VARCHAR )"
else:
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_for_category( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, False )"
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_for_category( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, False, (:observer)::VARCHAR )"
elif sort == 'comment_by_payout':
if tag == '':
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments( (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
else:
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments_for_category( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT )"
sql = "SELECT * FROM bridge_get_ranked_post_by_payout_comments_for_category( (:tag)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::SMALLINT, (:observer)::VARCHAR )"
else:
return posts
sql_result = await db.query_all(sql, tag=tag, author=start_author, permlink=start_permlink, limit=limit )
sql_result = await db.query_all(sql, tag=tag, author=start_author, permlink=start_permlink, limit=limit, observer=observer )
for row in sql_result:
post = _condenser_post_object(row, truncate_body)
......@@ -241,43 +242,43 @@ async def get_posts_by_given_sort(context, sort: str, start_author: str = '', st
@nested_query_compat
async def get_discussions_by_created(context, start_author: str = '', start_permlink: str = '',
limit: int = 20, tag: str = None,
truncate_body: int = 0, filter_tags: list = None):
return await get_posts_by_given_sort(context, 'created', start_author, start_permlink, limit, tag, truncate_body, filter_tags)
truncate_body: int = 0, filter_tags: list = None, observer:str=None):
return await get_posts_by_given_sort(context, 'created', start_author, start_permlink, limit, tag, truncate_body, filter_tags, observer)
@return_error_info
@nested_query_compat
async def get_discussions_by_trending(context, start_author: str = '', start_permlink: str = '',
limit: int = 20, tag: str = None,
truncate_body: int = 0, filter_tags: list = None):
return await get_posts_by_given_sort(context, 'trending', start_author, start_permlink, limit, tag, truncate_body, filter_tags)
truncate_body: int = 0, filter_tags: list = None, observer:str=None):
return await get_posts_by_given_sort(context, 'trending', start_author, start_permlink, limit, tag, truncate_body, filter_tags, observer)
@return_error_info
@nested_query_compat
async def get_discussions_by_hot(context, start_author: str = '', start_permlink: str = '',
limit: int = 20, tag: str = None,
truncate_body: int = 0, filter_tags: list = None):
return await get_posts_by_given_sort(context, 'hot', start_author, start_permlink, limit, tag, truncate_body, filter_tags)
truncate_body: int = 0, filter_tags: list = None, observer:str=None):
return await get_posts_by_given_sort(context, 'hot', start_author, start_permlink, limit, tag, truncate_body, filter_tags, observer)
@return_error_info
@nested_query_compat
async def get_discussions_by_promoted(context, start_author: str = '', start_permlink: str = '',
limit: int = 20, tag: str = None,
truncate_body: int = 0, filter_tags: list = None):
return await get_posts_by_given_sort(context, 'promoted', start_author, start_permlink, limit, tag, truncate_body, filter_tags)
truncate_body: int = 0, filter_tags: list = None, observer:str=None):
return await get_posts_by_given_sort(context, 'promoted', start_author, start_permlink, limit, tag, truncate_body, filter_tags, observer)
@return_error_info
@nested_query_compat
async def get_post_discussions_by_payout(context, start_author: str = '', start_permlink: str = '',
limit: int = 20, tag: str = None,
truncate_body: int = 0):
return await get_posts_by_given_sort(context, 'post_by_payout', start_author, start_permlink, limit, tag, truncate_body, [])
truncate_body: int = 0, observer:str=None):
return await get_posts_by_given_sort(context, 'post_by_payout', start_author, start_permlink, limit, tag, truncate_body, [], observer)
@return_error_info
@nested_query_compat
async def get_comment_discussions_by_payout(context, start_author: str = '', start_permlink: str = '',
limit: int = 20, tag: str = None,
truncate_body: int = 0):
return await get_posts_by_given_sort(context, 'comment_by_payout', start_author, start_permlink, limit, tag, truncate_body, [])
truncate_body: int = 0, observer:str=None):
return await get_posts_by_given_sort(context, 'comment_by_payout', start_author, start_permlink, limit, tag, truncate_body, [], observer)
@return_error_info
@nested_query_compat
......@@ -309,10 +310,10 @@ async def get_discussions_by_blog(context, tag: str = None, start_author: str =
return posts_by_id
async def get_discussions_by_feed_impl(db, account: str, start_author: str = '',
start_permlink: str = '', limit: int = 20, truncate_body: int = 0):
start_permlink: str = '', limit: int = 20, truncate_body: int = 0, observer:str=None):
"""Get a list of posts for an account's feed."""
sql = "SELECT * FROM bridge_get_by_feed_with_reblog((:account)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::INTEGER)"
result = await db.query_all(sql, account=account, author=start_author, permlink=start_permlink, limit=limit)
sql = "SELECT * FROM bridge_get_by_feed_with_reblog((:account)::VARCHAR, (:author)::VARCHAR, (:permlink)::VARCHAR, (:limit)::INTEGER, (:observer)::VARCHAR)"
result = await db.query_all(sql, account=account, author=start_author, permlink=start_permlink, limit=limit, observer=observer)
posts = []
for row in result:
......@@ -335,7 +336,7 @@ async def get_discussions_by_feed_impl(db, account: str, start_author: str = '',
@nested_query_compat
async def get_discussions_by_feed(context, tag: str = None, start_author: str = '',
start_permlink: str = '', limit: int = 20,
truncate_body: int = 0, filter_tags: list = None):
truncate_body: int = 0, filter_tags: list = None, observer:str=None):
"""Retrieve account's personalized feed."""
assert tag, '`tag` cannot be blank'
assert not filter_tags, 'filter_tags not supported'
......@@ -345,7 +346,7 @@ async def get_discussions_by_feed(context, tag: str = None, start_author: str =
valid_account(start_author, allow_empty=True),
valid_permlink(start_permlink, allow_empty=True),
valid_limit(limit, 100, 20),
truncate_body)
truncate_body, observer)
@return_error_info
@nested_query_compat
......
......@@ -38,13 +38,20 @@ class Db:
async def init(self, url):
"""Initialize the aiopg.sa engine."""
conf = make_url(url)
self.db = await create_engine(user=conf.username,
database=conf.database,
password=conf.password,
host=conf.host,
port=conf.port,
maxsize=20,
**conf.query)
dsn = {}
if conf.username:
dsn['user'] = conf.username
if conf.database:
dsn['database'] = conf.database
if conf.password:
dsn['password'] = conf.password
if conf.host:
dsn['host'] = conf.host
if conf.port:
dsn['port'] = conf.port
if 'application_name' not in conf.query:
dsn['application_name'] = 'hive_server'
self.db = await create_engine(**dsn, maxsize=20, **conf.query)
def close(self):
"""Close pool."""
......
#!/usr/local/bin/python3
#!/usr/bin/env python3
"""Hive profiling tools"""
import cProfile
......
#!/usr/bin/python3
#!/usr/bin/env python3
from json import dumps
......
#!/usr/bin/python3
#!/usr/bin/env python3
""" Parse json file generated by pytest benchmarks and create htm report file
for files exceeding expected threshold print information to the console
"""
......
#!/usr/bin/python3
#!/usr/bin/env python3
import os
import subprocess
from json import load, dump
......@@ -60,7 +60,7 @@ if __name__ == "__main__":
hivemind_url = "http://{}:{}".format(args.hivemind_address, args.hivemind_port)
test_directories = get_test_directories(args.tests_root_dir)
benchmarks_files = []
for test_directory in test_directories:
benchmark_file_name = "benchmark_" + test_directory.split("/")[-1] + ".py"
......
#!/usr/bin/python3
#!/usr/bin/env python3
"""
This script will scan blocks from range `from_block` to `to_block` if it finds operation defined in `operations` it will
save such block to a `output_file`. Blocks not containing any operations from list `operations` will be saved empty.
......
#!/usr/bin/python3
#!/usr/bin/env python3
import os
from xml.dom import minidom
......
#!/usr/bin/python3
#!/usr/bin/env python3
from test_base import run_test
......
#!/usr/bin/python3
#!/usr/bin/env python3
from test_base import run_test
if __name__ == '__main__':
......
#!/usr/bin/python3
#!/usr/bin/env python3
from test_base import run_test
if __name__ == '__main__':
......
#!/usr/bin/python3
#!/usr/bin/env python3
from test_base import run_test
if __name__ == '__main__':
......
#!/usr/bin/python3
#!/usr/bin/env python3
from test_base import run_test
if __name__ == '__main__':
......@@ -6,7 +6,7 @@ if __name__ == '__main__':
test_hive_node_url = 'http://127.0.0.1:8080'
payload = {
"jsonrpc" : "2.0",
"jsonrpc" : "2.0",
"method" : "database_api.list_comments",
"params" : {
"start" : ['steemit', 'firstpost', '', ''],
......