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
ff333971
Commit
ff333971
authored
4 years ago
by
Dariusz Kędzierski
Browse files
Options
Downloads
Patches
Plain Diff
Cache for votes, unique constraint fix for feed_cache
parent
b60dae12
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
+1
-0
1 addition, 0 deletions
hive/db/schema.py
hive/indexer/blocks.py
+2
-0
2 additions, 0 deletions
hive/indexer/blocks.py
hive/indexer/feed_cache.py
+1
-1
1 addition, 1 deletion
hive/indexer/feed_cache.py
hive/indexer/votes.py
+44
-24
44 additions, 24 deletions
hive/indexer/votes.py
with
48 additions
and
25 deletions
hive/db/schema.py
+
1
−
0
View file @
ff333971
...
...
@@ -266,6 +266,7 @@ def build_metadata():
sa
.
Column
(
'
account_id
'
,
sa
.
Integer
,
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
Index
(
'
hive_feed_cache_account_id
'
,
'
account_id
'
),
# API (and rebuild?)
sa
.
UniqueConstraint
(
'
account_id
'
,
'
post_id
'
,
name
=
'
hive_feed_cache_ux1
'
)
)
sa
.
Table
(
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/blocks.py
+
2
−
0
View file @
ff333971
...
...
@@ -38,6 +38,7 @@ class Blocks:
#assert is_trx_active(), "Block.process must be in a trx"
ret
=
cls
.
_process
(
block
,
vops_in_block
,
hived
,
is_initial_sync
=
False
)
PostDataCache
.
flush
()
Votes
.
flush
()
return
ret
@classmethod
...
...
@@ -57,6 +58,7 @@ class Blocks:
# expensive. So is tracking follows at all; hence we track
# deltas in memory and update follow/er counts in bulk.
PostDataCache
.
flush
()
Votes
.
flush
()
cls
.
_flush_blocks
()
Follow
.
flush
(
trx
=
False
)
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/feed_cache.py
+
1
−
1
View file @
ff333971
...
...
@@ -22,7 +22,7 @@ class FeedCache:
assert
not
DbState
.
is_initial_sync
(),
'
writing to feed cache in sync
'
sql
=
"""
INSERT INTO hive_feed_cache (account_id, post_id, created_at)
VALUES (:account_id, :id, :created_at)
ON CONFLICT
(account_id, post_id)
DO NOTHING
"""
ON CONFLICT
ON CONSTRAINT hive_feed_cache_ux1
DO NOTHING
"""
DB
.
query
(
sql
,
account_id
=
account_id
,
id
=
post_id
,
created_at
=
created_at
)
@classmethod
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/votes.py
+
44
−
24
View file @
ff333971
...
...
@@ -9,6 +9,7 @@ DB = Db.instance()
class
Votes
:
"""
Class for managing posts votes
"""
_votes_data
=
{}
@classmethod
def
get_vote_count
(
cls
,
author
,
permlink
):
...
...
@@ -57,28 +58,47 @@ class Votes:
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.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
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
)
key
=
voter
+
"
/
"
+
author
+
"
/
"
+
permlink
cls
.
_votes_data
[
key
]
=
dict
(
voter
=
voter
,
author
=
author
,
permlink
=
permlink
,
vote_percent
=
vop
[
'
value
'
][
'
vote_percent
'
],
weight
=
vop
[
'
value
'
][
'
weight
'
],
rshares
=
vop
[
'
value
'
][
'
rshares
'
],
last_update
=
date
)
@classmethod
def
flush
(
cls
):
"""
Flush vote data from cache to database
"""
if
cls
.
_votes_data
:
sql
=
"""
INSERT INTO hive_votes
(post_id, voter_id, author_id, permlink_id, weight, rshares, vote_percent, last_update)
"""
values
=
[]
for
_
,
vd
in
cls
.
_votes_data
.
items
():
values
.
append
(
"""
SELECT hp.id, ha_v.id, ha_a.id, hpd_p.id, {}, {}, {},
'
{}
'
::timestamp
FROM hive_accounts ha_v,
hive_posts hp
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 =
'
{}
'
AND hpd_p.permlink =
'
{}
'
AND ha_v.name =
'
{}
'
"""
.
format
(
vd
[
'
weight
'
],
vd
[
'
rshares
'
],
vd
[
'
vote_percent
'
],
vd
[
'
last_update
'
],
vd
[
'
author
'
],
vd
[
'
permlink
'
],
vd
[
'
voter
'
]))
sql
+=
'
UNION ALL
'
.
join
(
values
)
sql
+=
"""
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
)
cls
.
_votes_data
.
clear
()
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