mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-22 07:35:00 -05:00
remove user agent from data model, will just join on user_ips
This commit is contained in:
parent
d0857702e8
commit
dd1a832419
@ -15,6 +15,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
from dateutil import tz
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -354,10 +355,9 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
def _generate_user_daily_visits(txn):
|
def _generate_user_daily_visits(txn):
|
||||||
logger.info("Calling _generate_user_daily_visits")
|
logger.info("Calling _generate_user_daily_visits")
|
||||||
# determine timestamp of previous days
|
# determine timestamp of previous days
|
||||||
yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
|
yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=1)
|
||||||
yesterday_start = datetime.datetime(yesterday.year,
|
yesterday_start = datetime.datetime(yesterday.year, yesterday.month,
|
||||||
yesterday.month,
|
yesterday.day, tzinfo=tz.tzutc())
|
||||||
yesterday.day, 0, 0, 0, 0)
|
|
||||||
yesterday_start_time = int(time.mktime(yesterday_start.timetuple())) * 1000
|
yesterday_start_time = int(time.mktime(yesterday_start.timetuple())) * 1000
|
||||||
|
|
||||||
# Check that this job has not already been completed
|
# Check that this job has not already been completed
|
||||||
@ -371,9 +371,8 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
|
|
||||||
# Bail if the most recent time is yesterday
|
# Bail if the most recent time is yesterday
|
||||||
if row and row[0] == yesterday_start_time:
|
if row and row[0] == yesterday_start_time:
|
||||||
logger.info("Bailing from _generate_user_daily_visits, already completed")
|
|
||||||
return
|
return
|
||||||
logger.info("inserting into user_daily_visits")
|
|
||||||
# Not specificying an upper bound means that if the update is run at
|
# Not specificying an upper bound means that if the update is run at
|
||||||
# 10 mins past midnight and the user is active during a 30 min session
|
# 10 mins past midnight and the user is active during a 30 min session
|
||||||
# that the user is still included in the previous days stats
|
# that the user is still included in the previous days stats
|
||||||
@ -382,20 +381,20 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
# The alternative is to insert on every request - but prefer to avoid
|
# The alternative is to insert on every request - but prefer to avoid
|
||||||
# for performance reasons
|
# for performance reasons
|
||||||
sql = """
|
sql = """
|
||||||
SELECT user_id, user_agent, device_id
|
SELECT user_id, device_id
|
||||||
FROM user_ips
|
FROM user_ips
|
||||||
WHERE last_seen > ?
|
WHERE last_seen > ?
|
||||||
"""
|
"""
|
||||||
txn.execute(sql, (yesterday_start_time,))
|
txn.execute(sql, (yesterday_start_time,))
|
||||||
|
user_visits = txn.fetchall()
|
||||||
|
|
||||||
sql = """
|
sql = """
|
||||||
INSERT INTO user_daily_visits (user_id. user_agent,
|
INSERT INTO user_daily_visits (user_id, device_id, timestamp)
|
||||||
device_id, timestamp)
|
VALUES (?, ?, ?)
|
||||||
VALUES (?, ?, ?, ?)
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for row in txn:
|
for visit in user_visits:
|
||||||
txn.execute(sql, (row + (yesterday_start_time,)))
|
txn.execute(sql, (visit + (yesterday_start_time,)))
|
||||||
|
|
||||||
return self.runInteraction("generate_user_daily_visits",
|
return self.runInteraction("generate_user_daily_visits",
|
||||||
_generate_user_daily_visits)
|
_generate_user_daily_visits)
|
||||||
|
Loading…
Reference in New Issue
Block a user