Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Timo Ley
synapse
Commits
16d78be3
Commit
16d78be3
authored
6 years ago
by
Neil Johnson
Browse files
Options
Downloads
Patches
Plain Diff
make use of _simple_select_one_onecol, improved comments
parent
e40a510f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/storage/monthly_active_users.py
+11
-8
11 additions, 8 deletions
synapse/storage/monthly_active_users.py
synapse/storage/schema/delta/51/monthly_active_users.sql
+4
-0
4 additions, 0 deletions
synapse/storage/schema/delta/51/monthly_active_users.sql
with
15 additions
and
8 deletions
synapse/storage/monthly_active_users.py
+
11
−
8
View file @
16d78be3
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
from
twisted.internet
import
defer
from
twisted.internet
import
defer
from
synapse.util.caches.descriptors
import
cached
,
cachedInlineCallbacks
from
synapse.util.caches.descriptors
import
cached
from
._base
import
SQLBaseStore
from
._base
import
SQLBaseStore
...
@@ -104,7 +104,7 @@ class MonthlyActiveUsersStore(SQLBaseStore):
...
@@ -104,7 +104,7 @@ class MonthlyActiveUsersStore(SQLBaseStore):
self
.
_user_last_seen_monthly_active
.
invalidate
((
user_id
,))
self
.
_user_last_seen_monthly_active
.
invalidate
((
user_id
,))
self
.
get_monthly_active_count
.
invalidate
(())
self
.
get_monthly_active_count
.
invalidate
(())
@cached
InlineCallbacks
(
num_args
=
1
)
@cached
(
num_args
=
1
)
def
_user_last_seen_monthly_active
(
self
,
user_id
):
def
_user_last_seen_monthly_active
(
self
,
user_id
):
"""
"""
Checks if a given user is part of the monthly active user group
Checks if a given user is part of the monthly active user group
...
@@ -114,18 +114,16 @@ class MonthlyActiveUsersStore(SQLBaseStore):
...
@@ -114,18 +114,16 @@ class MonthlyActiveUsersStore(SQLBaseStore):
int : timestamp since last seen, None if never seen
int : timestamp since last seen, None if never seen
"""
"""
result
=
yield
self
.
_simple_select_onecol
(
return
(
self
.
_simple_select_one_onecol
(
table
=
"
monthly_active_users
"
,
table
=
"
monthly_active_users
"
,
keyvalues
=
{
keyvalues
=
{
"
user_id
"
:
user_id
,
"
user_id
"
:
user_id
,
},
},
retcol
=
"
timestamp
"
,
retcol
=
"
timestamp
"
,
allow_none
=
True
,
desc
=
"
_user_last_seen_monthly_active
"
,
desc
=
"
_user_last_seen_monthly_active
"
,
)
))
timestamp
=
None
if
len
(
result
)
>
0
:
timestamp
=
result
[
0
]
defer
.
returnValue
(
timestamp
)
@defer.inlineCallbacks
@defer.inlineCallbacks
def
populate_monthly_active_users
(
self
,
user_id
):
def
populate_monthly_active_users
(
self
,
user_id
):
...
@@ -140,6 +138,11 @@ class MonthlyActiveUsersStore(SQLBaseStore):
...
@@ -140,6 +138,11 @@ class MonthlyActiveUsersStore(SQLBaseStore):
last_seen_timestamp
=
yield
self
.
_user_last_seen_monthly_active
(
user_id
)
last_seen_timestamp
=
yield
self
.
_user_last_seen_monthly_active
(
user_id
)
now
=
self
.
hs
.
get_clock
().
time_msec
()
now
=
self
.
hs
.
get_clock
().
time_msec
()
# We want to reduce to the total number of db writes, and are happy
# to trade accuracy of timestamp in order to lighten load. This means
# We always insert new users (where MAU threshold has not been reached),
# but only update if we have not previously seen the user for
# LAST_SEEN_GRANULARITY ms
if
last_seen_timestamp
is
None
:
if
last_seen_timestamp
is
None
:
count
=
yield
self
.
get_monthly_active_count
()
count
=
yield
self
.
get_monthly_active_count
()
if
count
<
self
.
hs
.
config
.
max_mau_value
:
if
count
<
self
.
hs
.
config
.
max_mau_value
:
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/schema/delta/51/monthly_active_users.sql
+
4
−
0
View file @
16d78be3
...
@@ -16,6 +16,10 @@
...
@@ -16,6 +16,10 @@
-- a table of monthly active users, for use where blocking based on mau limits
-- a table of monthly active users, for use where blocking based on mau limits
CREATE
TABLE
monthly_active_users
(
CREATE
TABLE
monthly_active_users
(
user_id
TEXT
NOT
NULL
,
user_id
TEXT
NOT
NULL
,
-- Last time we saw the user. Not guaranteed to be accurate due to rate limiting
-- on updates, Granularity of updates governed by
-- syanpse.storage.monthly_active_users.LAST_SEEN_GRANULARITY
-- Measured in ms since epoch.
timestamp
BIGINT
NOT
NULL
timestamp
BIGINT
NOT
NULL
);
);
...
...
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