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
bfdfd3e7
Commit
bfdfd3e7
authored
4 years ago
by
Dariusz Kędzierski
Browse files
Options
Downloads
Patches
Plain Diff
Helper column for list_comments by_permlink, update to sql script
parent
b04c3d1e
No related branches found
No related tags found
5 merge requests
!456
Release candidate v1 24
,
!230
Setup monitoring with pghero
,
!135
Enable postgres monitoring on CI server
,
!16
Dk issue 3 concurrent block query rebase
,
!15
Dk issue 3 concurrent block query
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hive/db/schema.py
+2
-0
2 additions, 0 deletions
hive/db/schema.py
hive/indexer/cached_post.py
+2
-0
2 additions, 0 deletions
hive/indexer/cached_post.py
scripts/update_hivemind_db.sql
+27
-14
27 additions, 14 deletions
scripts/update_hivemind_db.sql
with
31 additions
and
14 deletions
hive/db/schema.py
+
2
−
0
View file @
bfdfd3e7
...
...
@@ -214,6 +214,8 @@ def build_metadata():
sa
.
Column
(
'
url
'
,
sa
.
Text
,
nullable
=
False
,
server_default
=
''
),
sa
.
Column
(
'
root_title
'
,
sa
.
String
(
255
),
nullable
=
False
,
server_default
=
''
),
sa
.
Column
(
'
author_permlink
'
,
sa
.
String
(
255
+
16
,
collation
=
'
C
'
),
nullable
=
False
,
server_default
=
''
),
# index: misc
sa
.
Index
(
'
hive_posts_cache_ix3
'
,
'
payout_at
'
,
'
post_id
'
,
postgresql_where
=
sql_text
(
"
is_paidout =
'
0
'"
)),
# core: payout sweep
sa
.
Index
(
'
hive_posts_cache_ix8
'
,
'
category
'
,
'
payout
'
,
'
depth
'
,
postgresql_where
=
sql_text
(
"
is_paidout =
'
0
'"
)),
# API: tag stats
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/cached_post.py
+
2
−
0
View file @
bfdfd3e7
...
...
@@ -503,6 +503,7 @@ class CachedPost:
(
'
is_paidout
'
,
basic
[
'
is_paidout
'
]),
(
'
json
'
,
json
.
dumps
(
basic
[
'
json_metadata
'
])),
#('raw_json', json.dumps(legacy_data)),
# TODO: check if writting fields below on every update is necessary!
(
'
legacy_id
'
,
legacy_data
[
'
id
'
]),
(
'
parent_author
'
,
legacy_data
[
'
parent_author
'
]),
(
'
parent_permlink
'
,
legacy_data
[
'
parent_permlink
'
]),
...
...
@@ -517,6 +518,7 @@ class CachedPost:
(
'
beneficiaries
'
,
json
.
dumps
(
legacy_data
[
'
beneficiaries
'
])),
(
'
url
'
,
legacy_data
[
'
url
'
]),
(
'
root_title
'
,
legacy_data
[
'
root_title
'
]),
(
'
author_permlink
'
,
post
[
'
author
'
]
+
post
[
'
permlink
'
]),
])
# if there's a pending promoted value to write, pull it out
...
...
This diff is collapsed.
Click to expand it.
scripts/update_hivemind_db.sql
+
27
−
14
View file @
bfdfd3e7
...
...
@@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS hive_db_version (
-- Upgrade to version 1.0
-- in this version we will move data from raw_json into separate columns
-- also it will add needed indexes and procedures
DO
$$
DECLARE
-- We will perform our operations in baches to conserve memory and CPU
...
...
@@ -42,7 +43,8 @@ DO $$
ADD
COLUMN
allow_curation_rewards
BOOLEAN
NOT
NULL
DEFAULT
TRUE
,
ADD
COLUMN
beneficiaries
JSON
NOT
NULL
DEFAULT
'[]'
,
ADD
COLUMN
url
TEXT
NOT
NULL
DEFAULT
''
,
ADD
COLUMN
root_title
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
;
ADD
COLUMN
root_title
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
ADD
COLUMN
author_permlink
VARCHAR
(
271
)
COLLATE
"C"
NOT
NULL
DEFAULT
''
;
RAISE
NOTICE
'Done...'
;
-- Helper type for use with json_populate_record
...
...
@@ -69,18 +71,27 @@ DO $$
WHILE
current_id
<
last_id
LOOP
RAISE
NOTICE
'Processing batch: % <= post_id < % (of %)'
,
current_id
,
current_id
+
batch_size
,
last_id
;
FOR
row
IN
SELECT
post_id
,
raw_json
FROM
hive_posts_cache
WHERE
post_id
>=
current_id
AND
post_id
<
current_id
+
batch_size
LOOP
UPDATE
hive_posts_cache
SET
(
legacy_id
,
parent_author
,
parent_permlink
,
curator_payout_value
,
root_author
,
root_permlink
,
max_accepted_payout
,
percent_steem_dollars
,
allow_replies
,
allow_votes
,
allow_curation_rewards
,
url
,
root_title
)
=
(
SELECT
id
,
parent_author
,
parent_permlink
,
curator_payout_value
,
root_author
,
root_permlink
,
max_accepted_payout
,
percent_steem_dollars
,
allow_replies
,
allow_votes
,
allow_curation_rewards
,
url
,
root_title
FROM
json_populate_record
(
null
::
legacy_comment_type
,
row
.
raw_json
::
json
)
)
WHERE
post_id
=
row
.
post_id
;
FOR
row
IN
SELECT
post_id
,
raw_json
,
author
,
permlink
FROM
hive_posts_cache
WHERE
post_id
>=
current_id
AND
post_id
<
current_id
+
batch_size
LOOP
UPDATE
hive_posts_cache
SET
legacy_id
=
jpr
.
id
,
parent_author
=
jpr
.
parent_author
,
parent_permlink
=
jpr
.
parent_permlink
,
curator_payout_value
=
jpr
.
curator_payout_value
,
root_author
=
jpr
.
root_author
,
root_permlink
=
jpr
.
root_permlink
,
max_accepted_payout
=
jpr
.
max_accepted_payout
,
percent_steem_dollars
=
jpr
.
percent_steem_dollars
,
allow_replies
=
jpr
.
allow_replies
,
allow_votes
=
jpr
.
allow_votes
,
allow_curation_rewards
=
jpr
.
allow_curation_rewards
,
beneficiaries
=
jpr
.
beneficiaries
,
url
=
jpr
.
url
,
root_title
=
jpr
.
root_title
,
author_permlink
=
(
row
.
author
||
row
.
permlink
)
FROM
json_populate_record
(
null
::
legacy_comment_type
,
row
.
raw_json
::
json
)
AS
jpr
WHERE
post_id
=
row
.
post_id
;
current_id
:
=
row
.
post_id
;
END
LOOP
;
END
LOOP
;
...
...
@@ -88,7 +99,6 @@ DO $$
-- Creating indexes
RAISE
NOTICE
'Creating author_permlink_idx'
;
CREATE
INDEX
IF
NOT
EXISTS
author_permlink_idx
ON
hive_posts_cache
(
author
ASC
,
permlink
ASC
);
CREATE
INDEX
IF
NOT
EXISTS
permlink_author_idx
ON
hive_posts_cache
(
permlink
ASC
,
author
ASC
);
RAISE
NOTICE
'Creating root_author_permlink_idx'
;
CREATE
INDEX
IF
NOT
EXISTS
root_author_permlink_idx
ON
hive_posts_cache
(
root_author
ASC
,
root_permlink
ASC
);
RAISE
NOTICE
'Creating parent_permlink_idx'
;
...
...
@@ -101,6 +111,9 @@ DO $$
CREATE
INDEX
IF
NOT
EXISTS
parent_updated_id_idx
ON
hive_posts_cache
(
parent_author
ASC
,
updated_at
ASC
,
post_id
ASC
);
RAISE
NOTICE
'Creating author_updated_id_idx'
;
CREATE
INDEX
IF
NOT
EXISTS
author_updated_id_idx
ON
hive_posts_cache
(
author
ASC
,
updated_at
ASC
,
post_id
ASC
);
-- idx for by_permlink list_comments
RAISE
NOTICE
'Creating author_permlink_col_idx'
;
CREATE
INDEX
IF
NOT
EXISTS
author_permlink_col_idx
ON
hive_comments_cache
(
author_permlink
ASC
);
-- Creating functions
-- for list_comments by_root
...
...
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