Skip to content
GitLab
Explore
Sign in
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
ce150a56
Commit
ce150a56
authored
5 years ago
by
roadscape
Browse files
Options
Downloads
Patches
Plain Diff
maintain accounts.rank field, close
#144
parent
6ed5ace5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hive/indexer/accounts.py
+13
-9
13 additions, 9 deletions
hive/indexer/accounts.py
hive/indexer/sync.py
+4
-3
4 additions, 3 deletions
hive/indexer/sync.py
with
17 additions
and
12 deletions
hive/indexer/accounts.py
+
13
−
9
View file @
ce150a56
...
@@ -26,6 +26,9 @@ class Accounts:
...
@@ -26,6 +26,9 @@ class Accounts:
# fifo queue
# fifo queue
_dirty
=
UniqueFIFO
()
_dirty
=
UniqueFIFO
()
# in-mem id->rank map
_ranks
=
{}
# account core methods
# account core methods
# --------------------
# --------------------
...
@@ -116,15 +119,11 @@ class Accounts:
...
@@ -116,15 +119,11 @@ class Accounts:
return
count
return
count
@classmethod
@classmethod
def
update_ranks
(
cls
):
def
fetch_ranks
(
cls
):
"""
Rebuild `hive_accounts` table rank-by-vote-weight column.
"""
"""
Rebuild account ranks and store in memory for next update.
"""
sql
=
"""
sql
=
"
SELECT id FROM hive_accounts ORDER BY vote_weight DESC
"
UPDATE hive_accounts
for
rank
,
_id
in
enumerate
(
DB
.
query_col
(
sql
)):
SET rank = r.rnk
cls
.
_ranks
[
_id
]
=
rank
+
1
FROM (SELECT id, ROW_NUMBER() OVER (ORDER BY vote_weight DESC) as rnk FROM hive_accounts) r
WHERE hive_accounts.id = r.id AND rank != r.rnk;
"""
DB
.
query
(
sql
)
@classmethod
@classmethod
def
_cache_accounts
(
cls
,
accounts
,
steem
,
trx
=
True
):
def
_cache_accounts
(
cls
,
accounts
,
steem
,
trx
=
True
):
...
@@ -186,5 +185,10 @@ class Accounts:
...
@@ -186,5 +185,10 @@ class Accounts:
'
raw_json
'
:
json
.
dumps
(
account
)}
'
raw_json
'
:
json
.
dumps
(
account
)}
# update rank field, if present
_id
=
cls
.
get_id
(
account
[
'
name
'
])
if
_id
in
cls
.
_ranks
:
values
[
'
rank
'
]
=
cls
.
_ranks
[
_id
]
bind
=
'
,
'
.
join
([
k
+
"
= :
"
+
k
for
k
in
list
(
values
.
keys
())][
1
:])
bind
=
'
,
'
.
join
([
k
+
"
= :
"
+
k
for
k
in
list
(
values
.
keys
())][
1
:])
return
(
"
UPDATE hive_accounts SET %s WHERE name = :name
"
%
bind
,
values
)
return
(
"
UPDATE hive_accounts SET %s WHERE name = :name
"
%
bind
,
values
)
This diff is collapsed.
Click to expand it.
hive/indexer/sync.py
+
4
−
3
View file @
ce150a56
...
@@ -39,8 +39,9 @@ class Sync:
...
@@ -39,8 +39,9 @@ class Sync:
# ensure db schema up to date, check app status
# ensure db schema up to date, check app status
DbState
.
initialize
()
DbState
.
initialize
()
# prefetch id->name memory map
# prefetch id->name
and id->rank
memory map
s
Accounts
.
load_ids
()
Accounts
.
load_ids
()
Accounts
.
fetch_ranks
()
if
DbState
.
is_initial_sync
():
if
DbState
.
is_initial_sync
():
# resume initial sync
# resume initial sync
...
@@ -189,8 +190,8 @@ class Sync:
...
@@ -189,8 +190,8 @@ class Sync:
cnt
[
'
insert
'
],
cnt
[
'
update
'
],
cnt
[
'
payout
'
],
cnt
[
'
upvote
'
],
cnt
[
'
insert
'
],
cnt
[
'
update
'
],
cnt
[
'
payout
'
],
cnt
[
'
upvote
'
],
cnt
[
'
recount
'
],
accts
,
follows
,
ms
,
'
SLOW
'
if
ms
>
1000
else
''
)
cnt
[
'
recount
'
],
accts
,
follows
,
ms
,
'
SLOW
'
if
ms
>
1000
else
''
)
#
if num % 1200 == 0: #1hr
if
num
%
1200
==
0
:
#1hr
#
Accounts.
update
_ranks()
#144
Accounts
.
fetch
_ranks
()
if
num
%
100
==
0
:
#5min
if
num
%
100
==
0
:
#5min
Accounts
.
dirty_oldest
(
500
)
Accounts
.
dirty_oldest
(
500
)
Accounts
.
flush
(
steemd
,
trx
=
True
)
Accounts
.
flush
(
steemd
,
trx
=
True
)
...
...
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