mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-06 11:34:59 -04:00
Add phone home stats for encrypted messages. (#9283)
Signed-off-by: Jan Christian Grünhage <jan.christian@gruenhage.xyz>
This commit is contained in:
parent
a800603561
commit
43dd93bb26
3 changed files with 64 additions and 2 deletions
|
@ -88,6 +88,62 @@ class ServerMetricsStore(EventPushActionsWorkerStore, SQLBaseStore):
|
|||
(x[0] - 1) * x[1] for x in res if x[1]
|
||||
)
|
||||
|
||||
async def count_daily_e2ee_messages(self):
|
||||
"""
|
||||
Returns an estimate of the number of messages sent in the last day.
|
||||
|
||||
If it has been significantly less or more than one day since the last
|
||||
call to this function, it will return None.
|
||||
"""
|
||||
|
||||
def _count_messages(txn):
|
||||
sql = """
|
||||
SELECT COALESCE(COUNT(*), 0) FROM events
|
||||
WHERE type = 'm.room.encrypted'
|
||||
AND stream_ordering > ?
|
||||
"""
|
||||
txn.execute(sql, (self.stream_ordering_day_ago,))
|
||||
(count,) = txn.fetchone()
|
||||
return count
|
||||
|
||||
return await self.db_pool.runInteraction("count_e2ee_messages", _count_messages)
|
||||
|
||||
async def count_daily_sent_e2ee_messages(self):
|
||||
def _count_messages(txn):
|
||||
# This is good enough as if you have silly characters in your own
|
||||
# hostname then thats your own fault.
|
||||
like_clause = "%:" + self.hs.hostname
|
||||
|
||||
sql = """
|
||||
SELECT COALESCE(COUNT(*), 0) FROM events
|
||||
WHERE type = 'm.room.encrypted'
|
||||
AND sender LIKE ?
|
||||
AND stream_ordering > ?
|
||||
"""
|
||||
|
||||
txn.execute(sql, (like_clause, self.stream_ordering_day_ago))
|
||||
(count,) = txn.fetchone()
|
||||
return count
|
||||
|
||||
return await self.db_pool.runInteraction(
|
||||
"count_daily_sent_e2ee_messages", _count_messages
|
||||
)
|
||||
|
||||
async def count_daily_active_e2ee_rooms(self):
|
||||
def _count(txn):
|
||||
sql = """
|
||||
SELECT COALESCE(COUNT(DISTINCT room_id), 0) FROM events
|
||||
WHERE type = 'm.room.encrypted'
|
||||
AND stream_ordering > ?
|
||||
"""
|
||||
txn.execute(sql, (self.stream_ordering_day_ago,))
|
||||
(count,) = txn.fetchone()
|
||||
return count
|
||||
|
||||
return await self.db_pool.runInteraction(
|
||||
"count_daily_active_e2ee_rooms", _count
|
||||
)
|
||||
|
||||
async def count_daily_messages(self):
|
||||
"""
|
||||
Returns an estimate of the number of messages sent in the last day.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue