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
b60dae12
Commit
b60dae12
authored
4 years ago
by
Dariusz Kędzierski
Browse files
Options
Downloads
Patches
Plain Diff
Merge with BW, merge fixes, simplification with post data cache
parent
785e2301
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
hive/db/schema.py
+5
-5
5 additions, 5 deletions
hive/db/schema.py
hive/indexer/blocks.py
+3
-1
3 additions, 1 deletion
hive/indexer/blocks.py
hive/indexer/posts.py
+7
-23
7 additions, 23 deletions
hive/indexer/posts.py
hive/indexer/votes.py
+15
-53
15 additions, 53 deletions
hive/indexer/votes.py
with
30 additions
and
82 deletions
hive/db/schema.py
+
5
−
5
View file @
b60dae12
...
...
@@ -161,11 +161,11 @@ def build_metadata():
sa
.
Table
(
'
hive_post_data
'
,
metadata
,
sa
.
Column
(
'
id
'
,
sa
.
Integer
,
primary_key
=
True
,
autoincrement
=
False
),
sa
.
Column
(
'
title
'
,
VARCHAR
(
255
),
server_default
=
''
),
sa
.
Column
(
'
preview
'
,
VARCHAR
(
1024
),
server_default
=
''
),
sa
.
Column
(
'
img_url
'
,
VARCHAR
(
1024
),
server_default
=
''
),
sa
.
Column
(
'
body
'
,
TEXT
,
server_default
=
''
),
sa
.
Column
(
'
json
'
,
TEXT
,
server_default
=
''
)
sa
.
Column
(
'
title
'
,
VARCHAR
(
255
),
nullable
=
False
,
server_default
=
''
),
sa
.
Column
(
'
preview
'
,
VARCHAR
(
1024
),
nullable
=
False
,
server_default
=
''
),
sa
.
Column
(
'
img_url
'
,
VARCHAR
(
1024
),
nullable
=
False
,
server_default
=
''
),
sa
.
Column
(
'
body
'
,
TEXT
,
nullable
=
False
,
server_default
=
''
),
sa
.
Column
(
'
json
'
,
TEXT
,
nullable
=
False
,
server_default
=
''
)
)
sa
.
Table
(
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/blocks.py
+
3
−
1
View file @
b60dae12
...
...
@@ -36,7 +36,9 @@ class Blocks:
def
process
(
cls
,
block
,
vops_in_block
,
hived
):
"""
Process a single block. Always wrap in a transaction!
"""
#assert is_trx_active(), "Block.process must be in a trx"
return
cls
.
_process
(
block
,
vops_in_block
,
hived
,
is_initial_sync
=
False
)
ret
=
cls
.
_process
(
block
,
vops_in_block
,
hived
,
is_initial_sync
=
False
)
PostDataCache
.
flush
()
return
ret
@classmethod
def
process_multi
(
cls
,
blocks
,
vops
,
hived
,
is_initial_sync
=
False
):
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/posts.py
+
7
−
23
View file @
b60dae12
...
...
@@ -107,34 +107,18 @@ class Posts:
cls
.
_set_id
(
op
[
'
author
'
]
+
'
/
'
+
op
[
'
permlink
'
],
result
[
'
id
'
])
# add content data to hive_post_data
if
DbState
.
is_initial_sync
():
post_data
=
dict
(
title
=
op
[
'
title
'
],
preview
=
op
[
'
preview
'
]
if
'
preview
'
in
op
else
""
,
img_url
=
op
[
'
img_url
'
]
if
'
img_url
'
in
op
else
""
,
body
=
op
[
'
body
'
],
json
=
op
[
'
json_metadata
'
]
if
op
[
'
json_metadata
'
]
else
'
{}
'
)
PostDataCache
.
add_data
(
result
[
'
id
'
],
post_data
)
else
:
sql
=
"""
INSERT INTO hive_post_data (id, title, preview, img_url, body, json)
VALUES (:id, :title, :preview, :img_url, :body, :json)
ON CONFLICT ON CONSTRAINT hive_post_data_pkey DO UPDATE SET
title = :title,
preview = :preview,
img_url = :img_url,
body = :body,
json = :json
"""
DB
.
query
(
sql
,
id
=
result
[
'
id
'
],
title
=
op
[
'
title
'
],
preview
=
op
[
'
preview
'
]
if
'
preview
'
in
op
else
""
,
img_url
=
op
[
'
img_url
'
]
if
'
img_url
'
in
op
else
""
,
body
=
op
[
'
body
'
],
json
=
op
[
'
json_metadata
'
]
if
op
[
'
json_metadata
'
]
else
'
{}
'
)
# add content data to hive_post_data
post_data
=
dict
(
title
=
op
[
'
title
'
],
preview
=
op
[
'
preview
'
]
if
'
preview
'
in
op
else
""
,
img_url
=
op
[
'
img_url
'
]
if
'
img_url
'
in
op
else
""
,
body
=
op
[
'
body
'
],
json
=
op
[
'
json_metadata
'
]
if
op
[
'
json_metadata
'
]
else
'
{}
'
)
PostDataCache
.
add_data
(
result
[
'
id
'
],
post_data
)
if
not
DbState
.
is_initial_sync
():
if
error
:
author_id
=
result
[
'
author_id
'
]
Notify
(
'
error
'
,
dst_id
=
author_id
,
when
=
date
,
Notify
(
'
error
'
,
dst_id
=
author_id
,
when
=
block_
date
,
post_id
=
result
[
'
id
'
],
payload
=
error
).
write
()
cls
.
_insert_feed_cache
(
result
,
date
)
cls
.
_insert_feed_cache
(
result
,
block_
date
)
@classmethod
def
comment_payout_op
(
cls
,
ops
,
date
):
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/votes.py
+
15
−
53
View file @
b60dae12
...
...
@@ -9,21 +9,6 @@ DB = Db.instance()
class
Votes
:
"""
Class for managing posts votes
"""
@classmethod
def
get_id
(
cls
,
voter
,
author
,
permlink
):
"""
Check if vote exists, if yes return its id, else return None
"""
sql
=
"""
SELECT
hv.id
FROM
hive_votes hv
INNER JOIN hive_accounts ha_v ON (ha_v.id = hv.voter_id)
INNER JOIN hive_accounts ha_a ON (ha_a.id = hv.author_id)
INNER JOIN hive_permlink_data hpd ON (hpd.id = hv.permlink_id)
WHERE ha_v.name = :voter AND ha_a.name = :author AND hpd.permlink = :permlink
"""
ret
=
DB
.
query_row
(
sql
,
voter
=
voter
,
author
=
author
,
permlink
=
permlink
)
return
None
if
ret
is
None
else
int
(
ret
.
id
)
@classmethod
def
get_vote_count
(
cls
,
author
,
permlink
):
...
...
@@ -72,51 +57,28 @@ class Votes:
voter
=
vop
[
'
value
'
][
'
voter
'
]
author
=
vop
[
'
value
'
][
'
author
'
]
permlink
=
vop
[
'
value
'
][
'
permlink
'
]
vote_id
=
cls
.
get_id
(
voter
,
author
,
permlink
)
# no vote so create new
if
vote_id
is
None
:
cls
.
_insert
(
vop
,
date
)
else
:
cls
.
_update
(
vote_id
,
vop
,
date
)
@classmethod
def
_insert
(
cls
,
vop
,
date
):
"""
Insert new vote
"""
voter
=
vop
[
'
value
'
][
'
voter
'
]
author
=
vop
[
'
value
'
][
'
author
'
]
permlink
=
vop
[
'
value
'
][
'
permlink
'
]
vote_percent
=
vop
[
'
value
'
][
'
vote_percent
'
]
weight
=
vop
[
'
value
'
][
'
weight
'
]
rshares
=
vop
[
'
value
'
][
'
rshares
'
]
sql
=
"""
INSERT INTO hive_votes
(post_id, voter_id, author_id, permlink_id, weight, rshares, vote_percent, last_update)
SELECT hp.id, ha_v.id, ha_a.id, hpd_p.id, :weight, :rshares, :vote_percent, :last_update
FROM hive_accounts ha_v,
hive_posts hp
INNER JOIN hive_accounts ha_a ON ha_a.
name
= hp.author
INNER JOIN hive_permlink_data hpd_p ON hpd_p.
permlink
= hp.permlink
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
WHERE ha_a.name = :author AND hpd_p.permlink = :permlink AND ha_v.name = :voter
"""
weight
=
vop
[
'
value
'
][
'
weight
'
]
rshares
=
vop
[
'
value
'
][
'
rshares
'
]
ON CONFLICT ON CONSTRAINT hive_votes_ux1 DO
UPDATE
SET
weight = EXCLUDED.weight,
rshares = EXCLUDED.rshares,
vote_percent = EXCLUDED.vote_percent,
last_update = EXCLUDED.last_update,
num_changes = hive_votes.num_changes + 1
WHERE hive_votes.id = EXCLUDED.id
"""
DB
.
query
(
sql
,
voter
=
voter
,
author
=
author
,
permlink
=
permlink
,
weight
=
weight
,
rshares
=
rshares
,
vote_percent
=
vote_percent
,
last_update
=
date
)
@classmethod
def
_update
(
cls
,
vote_id
,
vop
,
date
):
"""
Update existing vote
"""
vote_percent
=
vop
[
'
value
'
][
'
vote_percent
'
]
sql
=
"""
UPDATE hive_votes as hv
SET
weight = :weight,
rshares = :rshares,
vote_percent = :vote_percent,
last_update = :last_update,
num_changes = hv.num_changes + 1
WHERE hv.id = :id
"""
weight
=
vop
[
'
value
'
][
'
weight
'
]
rshares
=
vop
[
'
value
'
][
'
rshares
'
]
DB
.
query
(
sql
,
weight
=
weight
,
rshares
=
rshares
,
vote_percent
=
vote_percent
,
last_update
=
date
,
id
=
vote_id
)
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