-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Added middleware to track last_activity of a user #9554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
@@ -1172,6 +1172,7 @@ class TrackedShapeAttributeVal(AttributeVal): | |||
class Profile(models.Model): | |||
user = models.OneToOneField(User, on_delete=models.CASCADE) | |||
rating = models.FloatField(default=0.0) | |||
last_activity = models.DateTimeField(null=True, blank=True, default=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for consistency with other similar fields, it would be better to call this last_activity_date
.
@@ -787,3 +787,5 @@ class CVAT_QUEUES(Enum): | |||
"cron_string": "0 8 * * *", | |||
} | |||
) | |||
|
|||
USER_LAST_ACTIVITY_UPDATEP_PERIOD = timedelta(days=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
USER_LAST_ACTIVITY_UPDATEP_PERIOD = timedelta(days=1) | |
USER_LAST_ACTIVITY_UPDATE_PERIOD = timedelta(days=1) |
Also, I'm doubtful about using "period" here, because we don't update it periodically. Maybe something like MIN_INTERVAL
would be better?
@@ -24,3 +27,22 @@ def __call__(self, request): | |||
response.headers["X-Request-Id"] = request.uuid | |||
|
|||
return response | |||
|
|||
|
|||
class LastActivityMiddleware: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to add this to the middleware list.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #9554 +/- ##
===========================================
+ Coverage 73.76% 73.78% +0.01%
===========================================
Files 448 448
Lines 46695 46710 +15
Branches 3942 3942
===========================================
+ Hits 34446 34463 +17
+ Misses 12249 12247 -2
🚀 New features to boost your workflow:
|
Motivation and context
We need a robust way to define when user used CVAT service.
It seems
last_login
field in User model may not get updated for more than a year if user works every day and do not do any logins. It does not seem reliable. Also, different auth methods (basic, social, sso) and a lot of code around make it difficult to guarantee that this field gets updated always.Timestamps from analytics are not reliable also:
Finally, currently to find non-active users it is necessary to make many queries to the clickhouse database, so, usage report generation is much slower than with just postgres.
For me middleware with registering last activity once a day, seems the most reliable way.
How has this been tested?
Checklist
develop
branchLicense
Feel free to contact the maintainers if that's a concern.