Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Commits
fe4fa983
Commit
fe4fa983
authored
4 years ago
by
Bartek Wrona
Browse files
Options
Downloads
Patches
Plain Diff
List comments by parent opts
parent
eba04c89
No related branches found
Branches containing commit
No related tags found
Tags containing commit
3 merge requests
!456
Release candidate v1 24
,
!230
Setup monitoring with pghero
,
!135
Enable postgres monitoring on CI server
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
hive/db/db_state.py
+10
-0
10 additions, 0 deletions
hive/db/db_state.py
hive/db/schema.py
+121
-135
121 additions, 135 deletions
hive/db/schema.py
hive/indexer/blocks.py
+1
-0
1 addition, 0 deletions
hive/indexer/blocks.py
hive/indexer/posts.py
+2
-2
2 additions, 2 deletions
hive/indexer/posts.py
with
134 additions
and
137 deletions
hive/db/db_state.py
+
10
−
0
View file @
fe4fa983
...
@@ -205,6 +205,16 @@ class DbState:
...
@@ -205,6 +205,16 @@ class DbState:
time_end
=
perf_counter
()
time_end
=
perf_counter
()
log
.
info
(
"
[INIT] update_hive_posts_root_id executed in %fs
"
,
time_end
-
time_start
)
log
.
info
(
"
[INIT] update_hive_posts_root_id executed in %fs
"
,
time_end
-
time_start
)
time_start
=
perf_counter
()
# Update root_id all root posts
sql
=
"""
select update_hive_posts_api_helper(NULL, NULL)
"""
row
=
DbState
.
db
().
query_row
(
sql
)
time_end
=
perf_counter
()
log
.
info
(
"
[INIT] update_hive_posts_api_helper executed in %fs
"
,
time_end
-
time_start
)
time_start
=
perf_counter
()
time_start
=
perf_counter
()
...
...
This diff is collapsed.
Click to expand it.
hive/db/schema.py
+
121
−
135
View file @
fe4fa983
...
@@ -292,6 +292,15 @@ def build_metadata():
...
@@ -292,6 +292,15 @@ def build_metadata():
sa
.
Column
(
'
dgpo
'
,
sa
.
Text
,
nullable
=
False
),
sa
.
Column
(
'
dgpo
'
,
sa
.
Text
,
nullable
=
False
),
)
)
sa
.
Table
(
'
hive_posts_api_helper
'
,
metadata
,
sa
.
Column
(
'
id
'
,
sa
.
Integer
,
primary_key
=
True
,
autoincrement
=
False
),
sa
.
Column
(
'
author
'
,
VARCHAR
(
16
,
collation
=
'
C
'
),
nullable
=
False
),
sa
.
Column
(
'
parent_author
'
,
VARCHAR
(
16
,
collation
=
'
C
'
),
nullable
=
False
),
sa
.
Column
(
'
parent_permlink_or_category
'
,
sa
.
String
(
255
,
collation
=
'
C
'
),
nullable
=
False
),
sa
.
Index
(
'
hive_posts_api_helper_parent_permlink_or_category
'
,
'
parent_author
'
,
'
parent_permlink_or_category
'
,
'
id
'
)
)
metadata
=
build_metadata_community
(
metadata
)
metadata
=
build_metadata_community
(
metadata
)
return
metadata
return
metadata
...
@@ -557,21 +566,24 @@ def setup(db):
...
@@ -557,21 +566,24 @@ def setup(db):
db
.
query_no_return
(
sql
)
db
.
query_no_return
(
sql
)
sql
=
"""
sql
=
"""
DROP VIEW IF EXISTS public.hive_posts_
base_
view;
DROP VIEW IF EXISTS public.hive_posts_view;
CREATE OR REPLACE VIEW public.hive_posts_
base_
view
CREATE OR REPLACE VIEW public.hive_posts_view
AS
AS
SELECT hp.id,
SELECT hp.id,
hp.community_id,
hp.community_id,
hp.root_id,
hp.root_id,
hp.parent_id,
hp.parent_id,
hp.category_id,
hcd.category,
ha_a.name AS author,
ha_a.name AS author,
hp.active,
hp.active,
hp.author_rewards,
hp.author_rewards,
hp.author_id,
hp.author_id,
hpd_p.permlink,
hpd_p.permlink,
hpd.title,
hpd.body,
hpd.img_url,
hpd.preview,
hcd.category,
hp.depth,
hp.depth,
hp.promoted,
hp.promoted,
hp.payout,
hp.payout,
...
@@ -581,73 +593,10 @@ def setup(db):
...
@@ -581,73 +593,10 @@ def setup(db):
hp.cashout_time,
hp.cashout_time,
hp.is_paidout,
hp.is_paidout,
hp.children,
hp.children,
0 AS votes,
0 AS active_votes,
hp.created_at,
hp.created_at,
hp.updated_at,
hp.updated_at,
ha_a.reputation AS author_rep,
hp.is_hidden,
hp.is_grayed,
ha_pp.name AS parent_author,
CASE hp.depth > 0
WHEN true THEN hpd_pp.permlink
ELSE hcd.category
END AS parent_permlink_or_category,
hp.curator_payout_value,
hp.max_accepted_payout,
hp.percent_hbd,
true AS allow_replies,
hp.allow_votes,
hp.allow_curation_rewards,
hp.beneficiaries,
hp.sc_trend,
hp.sc_hot,
hp.counter_deleted,
hp.is_pinned,
hp.is_muted,
hp.is_nsfw,
hp.is_valid
FROM hive_posts hp
INNER JOIN hive_posts pp ON pp.id = hp.parent_id
INNER JOIN hive_accounts ha_a ON ha_a.id = hp.author_id
INNER JOIN hive_permlink_data hpd_p ON hpd_p.id = hp.permlink_id
INNER JOIN hive_accounts ha_pp ON ha_pp.id = pp.author_id
INNER JOIN hive_permlink_data hpd_pp ON hpd_pp.id = pp.permlink_id
LEFT OUTER JOIN hive_category_data hcd ON hcd.id = hp.category_id
;
"""
db
.
query_no_return
(
sql
)
sql
=
"""
DROP VIEW IF EXISTS public.hive_posts_view;
CREATE OR REPLACE VIEW public.hive_posts_view
AS
SELECT hp.id,
hp.community_id,
hp.root_id,
hp.parent_id,
ha_a.name AS author,
hp.active,
hp.author_rewards,
hp.author_id,
hpd_p.permlink,
hpd.title,
hpd.body,
hpd.img_url,
hpd.preview,
hcd.category,
hp.depth,
hp.promoted,
hp.payout,
hp.pending_payout,
hp.payout_at,
hp.last_payout_at,
hp.cashout_time,
hp.is_paidout,
hp.children,
0 AS votes,
0 AS active_votes,
hp.created_at,
hp.updated_at,
COALESCE(
COALESCE(
(
(
SELECT SUM( v.rshares )
SELECT SUM( v.rshares )
...
@@ -680,45 +629,46 @@ def setup(db):
...
@@ -680,45 +629,46 @@ def setup(db):
GROUP BY v.post_id
GROUP BY v.post_id
), 0
), 0
) AS net_votes,
) AS net_votes,
hpd.json,
hpd.json,
ha_a.reputation AS author_rep,
ha_a.reputation AS author_rep,
hp.is_hidden,
hp.is_hidden,
hp.is_grayed,
hp.is_grayed,
hp.total_vote_weight,
hp.total_vote_weight,
ha_pp.name AS parent_author,
ha_pp.name AS parent_author,
( CASE hp.depth > 0
( CASE hp.depth > 0
WHEN True THEN hpd_pp.permlink
WHEN True THEN hpd_pp.permlink
ELSE hcd.category
ELSE hcd.category
END ) AS parent_permlink_or_category,
END ) AS parent_permlink_or_category,
hp.curator_payout_value,
hp.curator_payout_value,
ha_rp.name AS root_author,
ha_rp.name AS root_author,
hpd_rp.permlink AS root_permlink,
hpd_rp.permlink AS root_permlink,
rcd.category as root_category,
rcd.category as root_category,
hp.max_accepted_payout,
hp.max_accepted_payout,
hp.percent_hbd,
hp.percent_hbd,
True AS allow_replies,
True AS allow_replies,
hp.allow_votes,
hp.allow_votes,
hp.allow_curation_rewards,
hp.allow_curation_rewards,
hp.beneficiaries,
hp.beneficiaries,
CONCAT(
'
/
'
, rcd.category,
'
/@
'
, ha_rp.name,
'
/
'
, hpd_rp.permlink,
CONCAT(
'
/
'
, rcd.category,
'
/@
'
, ha_rp.name,
'
/
'
, hpd_rp.permlink,
CASE (rp.id)
CASE (rp.id)
WHEN hp.id THEN
''
WHEN hp.id THEN
''
ELSE CONCAT(
'
#@
'
, ha_a.name,
'
/
'
, hpd_p.permlink)
ELSE CONCAT(
'
#@
'
, ha_a.name,
'
/
'
, hpd_p.permlink)
END
END
) AS url,
) AS url,
rpd.title AS root_title,
rpd.title AS root_title,
hp.sc_trend,
hp.sc_trend,
hp.sc_hot,
hp.sc_hot,
hp.counter_deleted,
hp.counter_deleted,
hp.is_pinned,
hp.is_pinned,
hp.is_muted,
hp.is_muted,
hp.is_nsfw,
hp.is_nsfw,
hp.is_valid,
hp.is_valid,
hr.title AS role_title,
hr.title AS role_title,
hr.role_id AS role_id,
hr.role_id AS role_id,
hc.title AS community_title,
hc.title AS community_title,
hc.name AS community_name
hc.name AS community_name,
FROM hive_posts hp
hp.block_num
FROM hive_posts hp
JOIN hive_posts pp ON pp.id = hp.parent_id
JOIN hive_posts pp ON pp.id = hp.parent_id
JOIN hive_posts rp ON rp.id = hp.root_id
JOIN hive_posts rp ON rp.id = hp.root_id
JOIN hive_accounts ha_a ON ha_a.id = hp.author_id
JOIN hive_accounts ha_a ON ha_a.id = hp.author_id
...
@@ -729,10 +679,10 @@ def setup(db):
...
@@ -729,10 +679,10 @@ def setup(db):
JOIN hive_accounts ha_rp ON ha_rp.id = rp.author_id
JOIN hive_accounts ha_rp ON ha_rp.id = rp.author_id
JOIN hive_permlink_data hpd_rp ON hpd_rp.id = rp.permlink_id
JOIN hive_permlink_data hpd_rp ON hpd_rp.id = rp.permlink_id
JOIN hive_post_data rpd ON rpd.id = rp.id
JOIN hive_post_data rpd ON rpd.id = rp.id
LEFT
JOIN hive_category_data hcd ON hcd.id = hp.category_id
JOIN hive_category_data hcd ON hcd.id = hp.category_id
LEFT
JOIN hive_category_data rcd ON rcd.id = rp.category_id
JOIN hive_category_data rcd ON rcd.id = rp.category_id
LEFT
OUTER
JOIN hive_communities hc ON
(
hp.community_id = hc.id
)
LEFT JOIN hive_communities hc ON hp.community_id = hc.id
LEFT
OUTER
JOIN hive_roles hr ON
(
hp.author_id = hr.account_id AND hp.community_id = hr.community_id
)
LEFT JOIN hive_roles hr ON hp.author_id = hr.account_id AND hp.community_id = hr.community_id
;
;
"""
"""
db
.
query_no_return
(
sql
)
db
.
query_no_return
(
sql
)
...
@@ -1024,42 +974,45 @@ def setup(db):
...
@@ -1024,42 +974,45 @@ def setup(db):
in _start_post_author hive_accounts.name%TYPE,
in _start_post_author hive_accounts.name%TYPE,
in _start_post_permlink hive_permlink_data.permlink%TYPE,
in _start_post_permlink hive_permlink_data.permlink%TYPE,
in _limit INT)
in _limit INT)
RETURNS SETOF database_api_post
RETURNS SETOF database_api_post
AS
LANGUAGE sql
$function$
DECLARE
COST 100
__post_id INT;
STABLE
BEGIN
ROWS 1000
__post_id = find_comment_id(_start_post_author,_start_post_permlink);
AS $BODY$
RETURN QUERY
SELECT
SELECT
hp.id, hp.community_id, hp.author, hp.permlink, hp.title, hp.body,
hp.id, hp.community_id, hp.author, hp.permlink, hp.title, hp.body,
hp.category, hp.depth, hp.promoted, hp.payout, hp.last_payout_at, hp.cashout_time, hp.is_paidout,
hp.category, hp.depth, hp.promoted, hp.payout, hp.last_payout_at, hp.cashout_time, hp.is_paidout,
hp.children, hp.votes, hp.created_at, hp.updated_at, hp.rshares, hp.json,
hp.children, hp.votes, hp.created_at, hp.updated_at, hp.rshares, hp.json,
hp.is_hidden, hp.is_grayed, hp.total_votes, hp.net_votes, hp.total_vote_weight,
hp.is_hidden, hp.is_grayed, hp.total_votes, hp.net_votes, hp.total_vote_weight,
hp.parent_author, hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink,
hp.parent_author, hp.parent_permlink_or_category, hp.curator_payout_value, hp.root_author, hp.root_permlink,
hp.max_accepted_payout, hp.percent_hbd, hp.allow_replies, hp.allow_votes,
hp.max_accepted_payout, hp.percent_hbd, hp.allow_replies, hp.allow_votes,
hp.allow_curation_rewards, hp.beneficiaries, hp.url, hp.root_title, hp.abs_rshares,
hp.allow_curation_rewards, hp.beneficiaries, hp.url, hp.root_title, hp.abs_rshares,
hp.active, hp.author_rewards
hp.active, hp.author_rewards
FROM
FROM
hive_posts_view hp
hive_posts_view hp
INNER JOIN
WHERE
(
NOT hp.is_muted AND
SELECT h.id FROM
hp.counter_deleted = 0 AND
hive_posts_api_helper h
parent_author > _parent_author OR
WHERE
parent_author = _parent_author AND ( parent_permlink_or_category > _parent_permlink OR
h.parent_author > _parent_author OR
parent_permlink_or_category = _parent_permlink AND hp.id >= __post_id )
h.parent_author = _parent_author AND ( h.parent_permlink_or_category > _parent_permlink OR
ORDER BY
h.parent_permlink_or_category = _parent_permlink AND h.id >= find_comment_id(_start_post_author,_start_post_permlink) )
parent_author ASC,
ORDER BY
parent_permlink_or_category ASC,
h.parent_author ASC,
id ASC
h.parent_permlink_or_category ASC,
LIMIT
h.id ASC
LIMIT
_limit
_limit
) ds ON ds.id = hp.id
WHERE
NOT hp.is_muted AND
hp.counter_deleted = 0
;
;
END
$BODY$;
$function$
;
LANGUAGE plpgsql
;
DROP FUNCTION IF EXISTS list_comments_by_last_update(character varying, timestamp, character varying, character varying, int)
DROP FUNCTION IF EXISTS list_comments_by_last_update(character varying, timestamp, character varying, character varying, int)
;
;
...
@@ -1327,6 +1280,39 @@ def setup(db):
...
@@ -1327,6 +1280,39 @@ def setup(db):
"""
"""
db
.
query_no_return
(
sql
)
db
.
query_no_return
(
sql
)
sql
=
"""
DROP FUNCTION IF EXISTS public.update_hive_posts_api_helper(INTEGER, INTEGER);
CREATE OR REPLACE FUNCTION public.update_hive_posts_api_helper(in _first_block_num INTEGER, _last_block_num INTEGER)
RETURNS void
LANGUAGE
'
plpgsql
'
VOLATILE
AS $BODY$
BEGIN
IF _first_block_num IS NULL OR _last_block_num IS NULL THEN
-- initial creation of table.
INSERT INTO hive_posts_api_helper
(id, author, parent_author, parent_permlink_or_category)
SELECT hp.id, hp.author, hp.parent_author, hp.parent_permlink_or_category
FROM hive_posts_view hp
;
ELSE
-- Regular incremental update.
INSERT INTO hive_posts_api_helper
(id, author, parent_author, parent_permlink_or_category)
SELECT hp.id, hp.author, hp.parent_author, hp.parent_permlink_or_category
FROM hive_posts_view hp
WHERE hp.block_num BETWEEN _first_block_num AND _last_block_num AND
NOT EXISTS (SELECT NULL FROM hive_posts_api_helper h WHERE h.id = hp.id)
;
END IF;
END
$BODY$
"""
db
.
query_no_return
(
sql
)
def
reset_autovac
(
db
):
def
reset_autovac
(
db
):
"""
Initializes/resets per-table autovacuum/autoanalyze params.
"""
Initializes/resets per-table autovacuum/autoanalyze params.
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/blocks.py
+
1
−
0
View file @
fe4fa983
...
@@ -404,3 +404,4 @@ class Blocks:
...
@@ -404,3 +404,4 @@ class Blocks:
update_active_starting_from_posts_on_block
(
first_block
,
last_block
)
update_active_starting_from_posts_on_block
(
first_block
,
last_block
)
DB
.
query
(
"
SELECT update_hive_posts_root_id({},{})
"
.
format
(
first_block
,
last_block
))
DB
.
query
(
"
SELECT update_hive_posts_root_id({},{})
"
.
format
(
first_block
,
last_block
))
DB
.
query
(
"
SELECT update_hive_posts_api_helper({},{})
"
.
format
(
first_block
,
last_block
))
This diff is collapsed.
Click to expand it.
hive/indexer/posts.py
+
2
−
2
View file @
fe4fa983
...
@@ -406,8 +406,8 @@ class Posts:
...
@@ -406,8 +406,8 @@ class Posts:
# populated with deleted posts somwrimas
# populated with deleted posts somwrimas
FeedCache
.
delete
(
pid
)
FeedCache
.
delete
(
pid
)
# force parent child recount when child is deleted
# force parent child recount when child is deleted
cls
.
update_child_count
(
pid
,
'
-
'
)
cls
.
update_child_count
(
pid
,
'
-
'
)
@classmethod
@classmethod
def
_insert_feed_cache
(
cls
,
result
,
date
):
def
_insert_feed_cache
(
cls
,
result
,
date
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment