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
987486f8
Commit
987486f8
authored
5 years ago
by
roadscape
Browse files
Options
Downloads
Patches
Plain Diff
add list_comms sort
parent
89ac82de
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hive/server/hive_api/community.py
+33
-19
33 additions, 19 deletions
hive/server/hive_api/community.py
with
33 additions
and
19 deletions
hive/server/hive_api/community.py
+
33
−
19
View file @
987486f8
...
@@ -139,40 +139,43 @@ async def list_subscribers(context, community):
...
@@ -139,40 +139,43 @@ async def list_subscribers(context, community):
str
(
r
[
'
created_at
'
]))
for
r
in
rows
]
str
(
r
[
'
created_at
'
]))
for
r
in
rows
]
@return_error_info
@return_error_info
async
def
list_communities
(
context
,
last
=
''
,
limit
=
100
,
query
=
None
,
observer
=
None
):
async
def
list_communities
(
context
,
last
=
''
,
limit
=
100
,
query
=
None
,
sort
=
'
rank
'
,
observer
=
None
):
"""
List all communities, paginated. Returns lite community list.
"""
"""
List all communities, paginated. Returns lite community list.
"""
# pylint: disable=too-many-arguments, too-many-locals
limit
=
valid_limit
(
limit
,
100
)
limit
=
valid_limit
(
limit
,
100
)
db
=
context
[
'
db
'
]
db
=
context
[
'
db
'
]
assert
not
query
,
'
query not yet supported
'
assert
not
query
,
'
query not yet supported
'
assert
sort
in
(
'
rank
'
,
'
new
'
,
'
subs
'
),
'
invalid sort
'
seek
=
''
where
=
[]
if
last
:
field
,
order
=
dict
(
seek
=
"""
AND rank > (SELECT rank
rank
=
(
'
rank
'
,
'
ASC
'
),
FROM hive_communities
new
=
(
'
created_at
'
,
'
DESC
'
),
WHERE name = :last)
"""
subs
=
(
'
subscribers
'
,
'
DESC
'
))[
sort
]
if
field
==
'
rank
'
:
where
.
append
(
'
rank > 0
'
)
sql
=
"""
SELECT id FROM hive_communities
if
last
:
WHERE rank > 0 AND (num_pending > 0 OR LENGTH(about) > 3) %s
field_cmp
=
'
>
'
if
order
==
'
ASC
'
else
'
<
'
ORDER BY rank LIMIT :limit
"""
%
seek
where
.
append
(
"""
%s %s (SELECT %s FROM hive_communities
WHERE name = :last)
"""
%
(
field
,
field_cmp
,
field
))
filt
=
'
WHERE
'
+
'
AND
'
.
join
(
where
)
if
where
else
''
sql
=
"""
SELECT id FROM hive_communities %s
ORDER BY %s %s LIMIT :limit
"""
%
(
filt
,
field
,
order
)
ids
=
await
db
.
query_col
(
sql
,
last
=
last
,
limit
=
limit
)
ids
=
await
db
.
query_col
(
sql
,
last
=
last
,
limit
=
limit
)
if
not
ids
:
return
[]
if
not
ids
:
return
[]
# append observer context, leadership data
communities
=
await
load_communities
(
db
,
ids
,
lite
=
True
)
communities
=
await
load_communities
(
db
,
ids
,
lite
=
True
)
if
observer
:
if
observer
:
observer_id
=
await
get_account_id
(
db
,
observer
)
observer_id
=
await
get_account_id
(
db
,
observer
)
await
_append_observer_subs
(
db
,
communities
,
observer_id
)
await
_append_observer_subs
(
db
,
communities
,
observer_id
)
await
_append_observer_roles
(
db
,
communities
,
observer_id
)
await
_append_observer_roles
(
db
,
communities
,
observer_id
)
await
_append_admins
(
db
,
communities
)
sql
=
"""
SELECT community_id, ha.name FROM hive_roles hr
JOIN hive_accounts ha ON hr.account_id = ha.id
WHERE role_id = 6 AND community_id IN :ids
"""
admins
=
await
db
.
query_all
(
sql
,
ids
=
tuple
(
ids
))
for
row
in
admins
:
_id
=
row
[
0
]
if
'
admins
'
not
in
communities
[
_id
]:
communities
[
_id
][
'
admins
'
]
=
list
()
communities
[
_id
][
'
admins
'
].
append
(
row
[
1
])
return
[
communities
[
_id
]
for
_id
in
ids
]
return
[
communities
[
_id
]
for
_id
in
ids
]
...
@@ -291,6 +294,17 @@ async def _append_observer_subs(db, communities, observer_id):
...
@@ -291,6 +294,17 @@ async def _append_observer_subs(db, communities, observer_id):
for
cid
,
comm
in
communities
.
items
():
for
cid
,
comm
in
communities
.
items
():
comm
[
'
context
'
][
'
subscribed
'
]
=
cid
in
subs
comm
[
'
context
'
][
'
subscribed
'
]
=
cid
in
subs
async
def
_append_admins
(
db
,
communities
):
ids
=
communities
.
keys
()
sql
=
"""
SELECT community_id, ha.name FROM hive_roles hr
JOIN hive_accounts ha ON hr.account_id = ha.id
WHERE role_id = 6 AND community_id IN :ids
"""
for
row
in
await
db
.
query_all
(
sql
,
ids
=
tuple
(
ids
)):
_id
=
row
[
0
]
if
'
admins
'
not
in
communities
[
_id
]:
communities
[
_id
][
'
admins
'
]
=
list
()
communities
[
_id
][
'
admins
'
].
append
(
row
[
1
])
# Stats
# Stats
# -----
# -----
...
...
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