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
4f38afb3
Commit
4f38afb3
authored
4 years ago
by
Mariusz Trela
Browse files
Options
Downloads
Patches
Plain Diff
An unification of presentation for find_votes/list_votes
parent
c42963fe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
4 merge requests
!456
Release candidate v1 24
,
!230
Setup monitoring with pghero
,
!138
Small typos fixed
,
!129
The calls 'list_votes'/'find_votes' work
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hive/server/database_api/methods.py
+21
-37
21 additions, 37 deletions
hive/server/database_api/methods.py
with
21 additions
and
37 deletions
hive/server/database_api/methods.py
+
21
−
37
View file @
4f38afb3
...
...
@@ -167,6 +167,25 @@ class VotesPresentation(Enum):
CondenserApi
=
3
BridgeApi
=
4
def
result_presentation
(
rows
,
votes_presentation
):
ret
=
[]
for
row
in
rows
:
if
votes_presentation
==
VotesPresentation
.
DatabaseApi
:
ret
.
append
(
dict
(
voter
=
row
.
voter
,
author
=
row
.
author
,
permlink
=
row
.
permlink
,
weight
=
row
.
weight
,
rshares
=
row
.
rshares
,
vote_percent
=
row
.
percent
,
last_update
=
str
(
row
.
time
),
num_changes
=
row
.
num_changes
))
elif
votes_presentation
==
VotesPresentation
.
CondenserApi
:
ret
.
append
(
dict
(
percent
=
str
(
row
.
percent
),
reputation
=
rep_to_raw
(
row
.
reputation
),
rshares
=
str
(
row
.
rshares
),
voter
=
row
.
voter
))
elif
votes_presentation
==
VotesPresentation
.
BridgeApi
:
ret
.
append
(
dict
(
rshares
=
str
(
row
.
rshares
),
voter
=
row
.
voter
))
else
:
ret
.
append
(
dict
(
percent
=
row
.
percent
,
reputation
=
rep_to_raw
(
row
.
reputation
),
rshares
=
number_to_json_value
(
row
.
rshares
),
time
=
time_string_with_t
(
row
.
time
),
voter
=
row
.
voter
,
weight
=
number_to_json_value
(
row
.
weight
)
))
return
ret
@return_error_info
async
def
find_votes
(
context
,
author
:
str
,
permlink
:
str
,
votes_presentation
=
VotesPresentation
.
DatabaseApi
):
"""
Returns all votes for the given post
"""
...
...
@@ -192,25 +211,8 @@ async def find_votes(context, author: str, permlink: str, votes_presentation = V
voter_id
"""
ret
=
[]
rows
=
await
db
.
query_all
(
sql
,
author
=
author
,
permlink
=
permlink
)
for
row
in
rows
:
if
votes_presentation
==
VotesPresentation
.
DatabaseApi
:
ret
.
append
(
dict
(
voter
=
row
.
voter
,
author
=
row
.
author
,
permlink
=
row
.
permlink
,
weight
=
row
.
weight
,
rshares
=
row
.
rshares
,
vote_percent
=
row
.
percent
,
last_update
=
str
(
row
.
time
),
num_changes
=
row
.
num_changes
))
elif
votes_presentation
==
VotesPresentation
.
CondenserApi
:
ret
.
append
(
dict
(
percent
=
str
(
row
.
percent
),
reputation
=
rep_to_raw
(
row
.
reputation
),
rshares
=
str
(
row
.
rshares
),
voter
=
row
.
voter
))
elif
votes_presentation
==
VotesPresentation
.
BridgeApi
:
ret
.
append
(
dict
(
rshares
=
str
(
row
.
rshares
),
voter
=
row
.
voter
))
else
:
ret
.
append
(
dict
(
percent
=
row
.
percent
,
reputation
=
rep_to_raw
(
row
.
reputation
),
rshares
=
number_to_json_value
(
row
.
rshares
),
time
=
time_string_with_t
(
row
.
time
),
voter
=
row
.
voter
,
weight
=
number_to_json_value
(
row
.
weight
)
))
return
ret
return
result_presentation
(
rows
,
votes_presentation
)
@return_error_info
async
def
list_votes
(
context
,
start
:
list
,
limit
:
int
,
order
:
str
,
votes_presentation
=
VotesPresentation
.
DatabaseApi
):
...
...
@@ -221,8 +223,6 @@ async def list_votes(context, start: list, limit: int, order: str, votes_present
assert
len
(
start
)
==
3
,
"
Expecting 3 elements in start array
"
db
=
context
[
'
db
'
]
ret
=
[]
sql
=
"""
SELECT
voter,
...
...
@@ -266,20 +266,4 @@ async def list_votes(context, start: list, limit: int, order: str, votes_present
"""
rows
=
await
db
.
query_all
(
sql
,
author
=
start
[
1
],
permlink
=
start
[
2
],
voter
=
start
[
0
],
limit
=
limit
)
for
row
in
rows
:
if
votes_presentation
==
VotesPresentation
.
DatabaseApi
:
ret
.
append
(
dict
(
voter
=
row
.
voter
,
author
=
row
.
author
,
permlink
=
row
.
permlink
,
weight
=
row
.
weight
,
rshares
=
row
.
rshares
,
vote_percent
=
row
.
percent
,
last_update
=
str
(
row
.
time
),
num_changes
=
row
.
num_changes
))
elif
votes_presentation
==
VotesPresentation
.
CondenserApi
:
ret
.
append
(
dict
(
percent
=
str
(
row
.
percent
),
reputation
=
rep_to_raw
(
row
.
reputation
),
rshares
=
str
(
row
.
rshares
),
voter
=
row
.
voter
))
elif
votes_presentation
==
VotesPresentation
.
BridgeApi
:
ret
.
append
(
dict
(
rshares
=
str
(
row
.
rshares
),
voter
=
row
.
voter
))
else
:
ret
.
append
(
dict
(
percent
=
row
.
percent
,
reputation
=
rep_to_raw
(
row
.
reputation
),
rshares
=
number_to_json_value
(
row
.
rshares
),
time
=
time_string_with_t
(
row
.
time
),
voter
=
row
.
voter
,
weight
=
number_to_json_value
(
row
.
weight
)
))
return
ret
return
result_presentation
(
rows
,
votes_presentation
)
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