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
67935e72
Commit
67935e72
authored
4 years ago
by
Mariusz Trela
Browse files
Options
Downloads
Patches
Plain Diff
Not used methods are removed
parent
067b48a0
No related branches found
No related tags found
2 merge requests
!456
Release candidate v1 24
,
!347
Refactoring + additional SQL functions
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
hive/server/condenser_api/cursor.py
+0
-12
0 additions, 12 deletions
hive/server/condenser_api/cursor.py
hive/server/hive_api/common.py
+0
-18
0 additions, 18 deletions
hive/server/hive_api/common.py
hive/server/hive_api/thread.py
+0
-134
0 additions, 134 deletions
hive/server/hive_api/thread.py
with
0 additions
and
164 deletions
hive/server/condenser_api/cursor.py
+
0
−
12
View file @
67935e72
...
...
@@ -7,18 +7,6 @@ from hive.server.database_api.methods import find_votes_impl, VotesPresentation
# pylint: disable=too-many-lines
async
def
get_post_id
(
db
,
author
,
permlink
):
"""
Given an author/permlink, retrieve the id from db.
"""
sql
=
"""
SELECT
hp.id
FROM 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 counter_deleted = 0 LIMIT 1
"""
# ABW: replace with find_comment_id(:author,:permlink,True)?
return
await
db
.
query_one
(
sql
,
author
=
author
,
permlink
=
permlink
)
async
def
get_followers
(
db
,
account
:
str
,
start
:
str
,
follow_type
:
str
,
limit
:
int
):
"""
Get a list of accounts following by a given account.
"""
state
=
2
if
follow_type
==
'
ignore
'
else
1
...
...
This diff is collapsed.
Click to expand it.
hive/server/hive_api/common.py
+
0
−
18
View file @
67935e72
...
...
@@ -17,24 +17,6 @@ async def get_community_id(db, name):
return
await
db
.
query_one
(
"
SELECT id FROM hive_communities WHERE name = :name
"
,
name
=
name
)
async
def
url_to_id
(
db
,
url
):
"""
Get post_id based on post url.
"""
return
await
get_post_id
(
db
,
*
split_url
(
url
))
async
def
get_post_id
(
db
,
author
,
permlink
):
"""
Get post_id based on author/permlink.
"""
sql
=
"""
SELECT
hp.id, ha_a.name as author, hpd_p.permlink as permlink
FROM
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 = :a AND hpd_p.permlink = :p
"""
_id
=
await
db
.
query_one
(
sql
,
a
=
author
,
p
=
permlink
)
assert
_id
,
'
post id not found
'
return
_id
async
def
get_account_id
(
db
,
name
):
"""
Get account id from account name.
"""
assert
name
,
'
no account name specified
'
...
...
This diff is collapsed.
Click to expand it.
hive/server/hive_api/thread.py
deleted
100644 → 0
+
0
−
134
View file @
067b48a0
"""
Hive API: Threaded discussion handling
"""
import
logging
from
hive.server.hive_api.common
import
url_to_id
,
valid_comment_sort
,
valid_limit
from
hive.server.hive_api.objects
import
comments_by_id
log
=
logging
.
getLogger
(
__name__
)
# pylint: disable=too-many-arguments
async
def
fetch_tree
(
context
,
root
,
sort
=
'
top
'
,
limit
=
20
,
observer
=
None
):
"""
Fetch comment tree. Includes comments and lite author data.
If community: follows/applies mod rules
If blog: hides comments by any muted accounts of the author
'
s
Sort: new, old, hot, payout
"""
db
=
context
[
'
db
'
]
root_id
=
await
url_to_id
(
db
,
root
)
return
await
_fetch_children
(
db
,
root_id
,
None
,
valid_comment_sort
(
sort
),
valid_limit
(
limit
,
50
,
20
),
observer
)
async
def
fetch_more_children
(
context
,
root_id
,
last_sibling_id
,
sort
=
'
top
'
,
limit
=
20
,
observer
=
None
):
"""
Fetch truncated siblings from tree.
"""
db
=
context
[
'
db
'
]
return
await
_fetch_children
(
db
,
root_id
,
last_sibling_id
,
valid_comment_sort
(
sort
),
valid_limit
(
limit
,
50
,
20
),
observer
)
_SORTS
=
dict
(
hot
=
'
sc_hot
'
,
top
=
'
payout
'
,
new
=
'
id
'
)
async
def
_fetch_children
(
db
,
root_id
,
start_id
,
sort
,
limit
,
observer
=
None
):
"""
Fetch truncated children from tree.
"""
mutes
=
set
()
field
=
_SORTS
[
sort
]
# load id skeleton
tree
,
parent
=
await
_load_tree
(
db
,
root_id
,
mutes
,
max_depth
=
3
)
# find most relevant ids in subset
seek
=
''
if
start_id
:
seek
=
"""
AND %s < (SELECT %s FROM hive_posts
WHERE id = :start_id)
"""
%
(
field
,
field
)
sql
=
"""
SELECT id FROM hive_posts
WHERE id IN :ids %s ORDER BY %s DESC
LIMIT :limit
"""
%
(
seek
,
field
)
relevant_ids
=
await
db
.
query_col
(
sql
,
ids
=
tuple
(
parent
.
keys
()),
start_id
=
start_id
,
limit
=
limit
)
# fill in missing parents
for
_id
in
relevant_ids
:
if
_id
!=
root_id
:
if
parent
[
_id
]
not
in
relevant_ids
:
relevant_ids
.
append
(
parent
[
_id
])
# load objects and assemble response tree
comments
=
await
comments_by_id
(
db
,
relevant_ids
,
observer
)
return
{
'
accounts
'
:
comments
[
'
accounts
'
],
'
posts
'
:
_build_tree
(
tree
[
root_id
],
tree
,
comments
[
'
posts
'
],
sort_ids
=
relevant_ids
)}
def
_build_tree
(
root_ids
,
tree
,
comments
,
sort_ids
):
# comments is sorted...
ret
=
[]
for
root_id
in
sorted
(
root_ids
,
key
=
sort_ids
.
index
):
assert
root_id
in
comments
,
'
root not loaded
'
out
=
comments
[
root_id
]
out
[
'
type
'
]
=
'
comment
'
if
root_id
in
tree
:
missing
=
0
loaded_ids
=
[]
for
cid
in
tree
[
root_id
]:
if
cid
in
comments
:
assert
not
missing
,
'
missing mode: not expected to find
'
loaded_ids
.
append
(
cid
)
else
:
missing
+=
1
if
loaded_ids
:
out
[
'
children
'
]
=
_build_tree
(
loaded_ids
,
tree
,
comments
,
sort_ids
)
else
:
out
[
'
children
'
]
=
[]
if
missing
:
last_id
=
loaded_ids
[
-
1
]
if
loaded_ids
else
None
out
[
'
children
'
].
append
({
'
type
'
:
'
more-children
'
,
'
root_id
'
:
root_id
,
'
last_id
'
:
last_id
,
'
count
'
:
missing
})
ret
.
append
(
out
)
return
ret
async
def
_load_tree
(
db
,
root_id
,
muted
,
max_depth
):
"""
Build `ids` list and `tree` map.
"""
parent
=
{}
# only loaded to max_depth
tree
=
{}
# loaded to max_depth + 1
todo
=
[
root_id
]
depth
=
0
while
todo
:
depth
+=
1
rows
=
await
_child_ids
(
db
,
todo
,
muted
)
todo
=
[]
for
pid
,
cids
in
rows
:
tree
[
pid
]
=
cids
todo
.
extend
(
cids
)
if
depth
<=
max_depth
:
for
cid
in
cids
:
parent
[
cid
]
=
pid
if
depth
>
max_depth
:
break
return
(
tree
,
parent
)
async
def
_child_ids
(
db
,
parent_ids
,
muted
):
"""
Load child ids for multiple parent ids.
"""
filt
=
'
AND author NOT IN :muted
'
if
muted
else
''
sql
=
"""
SELECT parent_id, array_agg(id)
FROM hive_posts
WHERE parent_id IN :ids
AND counter_deleted = 0
AND is_muted =
'
0
'
AND is_valid =
'
1
'
%s
GROUP BY parent_id
"""
%
filt
rows
=
await
db
.
query_all
(
sql
,
ids
=
tuple
(
parent_ids
),
muted
=
tuple
(
muted
))
return
[[
row
[
0
],
row
[
1
]]
for
row
in
rows
]
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