From bcb4a8e9bdb310a9edd7574f5ecdc90de53026c6 Mon Sep 17 00:00:00 2001 From: stuppie Date: Mon, 26 Oct 2026 11:16:51 -0600 Subject: new timestamp fields on user table --- generalresearch/thl_django/common/models.py | 38 ++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/generalresearch/thl_django/common/models.py b/generalresearch/thl_django/common/models.py index afbe722..6f8f813 100644 --- a/generalresearch/thl_django/common/models.py +++ b/generalresearch/thl_django/common/models.py @@ -305,14 +305,25 @@ class THLUser(models.Model): # This will be useful for looking at signups per country globally. created = models.DateTimeField(null=False) - # This will be useful as our Daily Active User metric (DAU) that a lot - # of marketplaces want reported on. We'll be able to change the - # logic for when this is updated, but keeping it in a table will - # make queries much easier. - # We'll force null=True, and his will be the same as created - # until they're "seen again". + # The most recent time the user started a task or returned from a marketplace + # redirect. This is initialized to `created` and can be used to report users + # who were recently active in tasks. last_seen = models.DateTimeField(null=False) + # The time the user most recently completed a task. + last_task_completed_at = models.DateTimeField(null=True) + + # The time of the user's most recent offerwall request. Database writes are + # rate-limited through Redis to at most once per minute to reduce table churn, + # so this value may lag the latest request by up to one minute. + last_offerwall_requested_at = models.DateTimeField(null=True) + + # The time the user most recently submitted profiling answers, either during + # a GRS session or directly through the API. Database writes are rate-limited + # through Redis to at most once per minute, so this value may lag the latest + # submission by up to one minute. + last_profiling_submission_at = models.DateTimeField(null=True) + # this isn't used for any security measures, but we have an increasing # need to provide a "live panel book" to describe our user base. This # will help immediately filter users down by "after users from X country @@ -352,6 +363,21 @@ class THLUser(models.Model): # models.Index(fields=["product_id", "product_user_id"]), models.Index(fields=["created"]), models.Index(fields=["last_seen"]), + models.Index( + fields=["last_task_completed_at"], + name="thl_user_last_task_comp_nn", + condition=Q(last_task_completed_at__isnull=False), + ), + models.Index( + fields=["last_offerwall_requested_at"], + name="thl_user_last_offerwall_nn", + condition=Q(last_offerwall_requested_at__isnull=False), + ), + models.Index( + fields=["last_profiling_submission_at"], + name="thl_user_last_profile_nn", + condition=Q(last_profiling_submission_at__isnull=False), + ), models.Index(fields=["last_country_iso"]), ] -- cgit v1.2.3