Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
f8aae79a
Commit
f8aae79a
authored
9 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Simplify get_rooms
parent
9cd80a7b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
synapse/app/homeserver.py
+2
-2
2 additions, 2 deletions
synapse/app/homeserver.py
synapse/storage/room.py
+7
-77
7 additions, 77 deletions
synapse/storage/room.py
tests/storage/test_room.py
+0
-26
0 additions, 26 deletions
tests/storage/test_room.py
with
9 additions
and
105 deletions
synapse/app/homeserver.py
+
2
−
2
View file @
f8aae79a
...
...
@@ -674,8 +674,8 @@ def run(hs):
stats
[
"
uptime_seconds
"
]
=
uptime
stats
[
"
total_users
"
]
=
yield
hs
.
get_datastore
().
count_all_users
()
all_rooms
=
yield
hs
.
get_datastore
().
get_room
s
(
False
)
stats
[
"
total_room_count
"
]
=
len
(
all_rooms
)
room_count
=
yield
hs
.
get_datastore
().
get_room
_count
(
)
stats
[
"
total_room_count
"
]
=
room_count
stats
[
"
daily_active_users
"
]
=
yield
hs
.
get_datastore
().
count_daily_users
()
daily_messages
=
yield
hs
.
get_datastore
().
count_daily_messages
()
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/room.py
+
7
−
77
View file @
f8aae79a
...
...
@@ -87,90 +87,20 @@ class RoomStore(SQLBaseStore):
desc
=
"
get_public_room_ids
"
,
)
@defer.inlineCallbacks
def
get_rooms
(
self
,
is_public
):
"""
Retrieve a list of all public rooms.
Args:
is_public (bool): True if the rooms returned should be public.
Returns:
A list of room dicts containing at least a
"
room_id
"
key, a
"
topic
"
key if one is set, and a
"
name
"
key if one is set
def
get_room_count
(
self
):
"""
Retrieve a list of all rooms
"""
def
f
(
txn
):
def
subquery
(
table_name
,
column_name
=
None
):
column_name
=
column_name
or
table_name
return
(
"
SELECT %(table_name)s.event_id as event_id,
"
"
%(table_name)s.room_id as room_id, %(column_name)s
"
"
FROM %(table_name)s
"
"
INNER JOIN current_state_events as c
"
"
ON c.event_id = %(table_name)s.event_id
"
%
{
"
column_name
"
:
column_name
,
"
table_name
"
:
table_name
,
}
)
sql
=
(
"
SELECT
"
"
r.room_id,
"
"
max(n.name),
"
"
max(t.topic),
"
"
max(v.history_visibility),
"
"
max(g.guest_access)
"
"
FROM rooms AS r
"
"
LEFT JOIN (%(topic)s) AS t ON t.room_id = r.room_id
"
"
LEFT JOIN (%(name)s) AS n ON n.room_id = r.room_id
"
"
LEFT JOIN (%(history_visibility)s) AS v ON v.room_id = r.room_id
"
"
LEFT JOIN (%(guest_access)s) AS g ON g.room_id = r.room_id
"
"
WHERE r.is_public = ?
"
"
GROUP BY r.room_id
"
%
{
"
topic
"
:
subquery
(
"
topics
"
,
"
topic
"
),
"
name
"
:
subquery
(
"
room_names
"
,
"
name
"
),
"
history_visibility
"
:
subquery
(
"
history_visibility
"
),
"
guest_access
"
:
subquery
(
"
guest_access
"
),
}
)
txn
.
execute
(
sql
,
(
is_public
,))
rows
=
txn
.
fetchall
()
for
i
,
row
in
enumerate
(
rows
):
room_id
=
row
[
0
]
aliases
=
self
.
_simple_select_onecol_txn
(
txn
,
table
=
"
room_aliases
"
,
keyvalues
=
{
"
room_id
"
:
room_id
},
retcol
=
"
room_alias
"
,
)
sql
=
"
SELECT count(*) FROM rooms
"
txn
.
execute
(
sql
)
row
=
txn
.
fetchone
()
return
row
[
0
]
or
0
rows
[
i
]
=
list
(
row
)
+
[
aliases
]
return
rows
rows
=
yield
self
.
runInteraction
(
return
self
.
runInteraction
(
"
get_rooms
"
,
f
)
ret
=
[
{
"
room_id
"
:
r
[
0
],
"
name
"
:
r
[
1
],
"
topic
"
:
r
[
2
],
"
world_readable
"
:
r
[
3
]
==
"
world_readable
"
,
"
guest_can_join
"
:
r
[
4
]
==
"
can_join
"
,
"
aliases
"
:
r
[
5
],
}
for
r
in
rows
if
r
[
5
]
# We only return rooms that have at least one alias.
]
defer
.
returnValue
(
ret
)
def
_store_room_topic_txn
(
self
,
txn
,
event
):
if
hasattr
(
event
,
"
content
"
)
and
"
topic
"
in
event
.
content
:
self
.
_simple_insert_txn
(
...
...
This diff is collapsed.
Click to expand it.
tests/storage/test_room.py
+
0
−
26
View file @
f8aae79a
...
...
@@ -51,32 +51,6 @@ class RoomStoreTestCase(unittest.TestCase):
(
yield
self
.
store
.
get_room
(
self
.
room
.
to_string
()))
)
@defer.inlineCallbacks
def
test_get_rooms
(
self
):
# get_rooms does an INNER JOIN on the room_aliases table :(
rooms
=
yield
self
.
store
.
get_rooms
(
is_public
=
True
)
# Should be empty before we add the alias
self
.
assertEquals
([],
rooms
)
yield
self
.
store
.
create_room_alias_association
(
room_alias
=
self
.
alias
,
room_id
=
self
.
room
.
to_string
(),
servers
=
[
"
test
"
]
)
rooms
=
yield
self
.
store
.
get_rooms
(
is_public
=
True
)
self
.
assertEquals
(
1
,
len
(
rooms
))
self
.
assertEquals
({
"
name
"
:
None
,
"
room_id
"
:
self
.
room
.
to_string
(),
"
topic
"
:
None
,
"
aliases
"
:
[
self
.
alias
.
to_string
()],
"
world_readable
"
:
False
,
"
guest_can_join
"
:
False
,
},
rooms
[
0
])
class
RoomEventsStoreTestCase
(
unittest
.
TestCase
):
...
...
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