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
31c2502c
Commit
31c2502c
authored
6 years ago
by
Neil Johnson
Browse files
Options
Downloads
Patches
Plain Diff
style and further contraining query
parent
c92a8aa5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/__init__.py
+12
-8
12 additions, 8 deletions
synapse/storage/__init__.py
with
12 additions
and
8 deletions
synapse/storage/__init__.py
+
12
−
8
View file @
31c2502c
...
...
@@ -368,6 +368,7 @@ class DataStore(RoomMemberStore, RoomStore,
logger
.
info
(
"
Calling _generate_user_daily_visits
"
)
today_start
=
self
.
_get_start_of_day
()
a_day_in_milliseconds
=
24
*
60
*
60
*
1000
now
=
self
.
clock
.
time_msec
()
sql
=
"""
INSERT INTO user_daily_visits (user_id, device_id, timestamp)
...
...
@@ -386,23 +387,26 @@ class DataStore(RoomMemberStore, RoomStore,
# where if the user logs in at 23:59 and overwrites their
# last_seen at 00:01 then they will not be counted in the
# previous day's stats - it is important that the query is run
# to minimise this case.
#
often
to minimise this case.
if
today_start
>
self
.
_last_user_visit_update
:
yesterday_start
=
today_start
-
a_day_in_milliseconds
txn
.
execute
(
sql
,
(
yesterday_start
,
yesterday_start
,
self
.
_last_user_visit_update
,
today_start
))
txn
.
execute
(
sql
,
(
yesterday_start
,
yesterday_start
,
self
.
_last_user_visit_update
,
today_start
))
self
.
_last_user_visit_update
=
today_start
txn
.
execute
(
sql
,
(
today_start
,
today_start
,
self
.
_last_user_visit_update
,
today_start
+
a_day_in_milliseconds
))
txn
.
execute
(
sql
,
(
today_start
,
today_start
,
self
.
_last_user_visit_update
,
now
))
# Update _last_user_visit_update to now. The reason to do this
# rather just clamping to the beginning of the day is to limit
# the size of the join - meaning that the query can be run more
# frequently
now
=
datetime
.
datetime
.
utcnow
()
self
.
_last_user_visit_update
=
int
(
time
.
mktime
(
now
.
timetuple
()))
*
1000
self
.
_last_user_visit_update
=
now
return
self
.
runInteraction
(
"
generate_user_daily_visits
"
,
_generate_user_daily_visits
)
...
...
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