-
Notifications
You must be signed in to change notification settings - Fork 69
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
fix: online status middleware cache #955
Conversation
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.
Reviewed 10 of 93 files at r1.
Reviewable status: 10 of 93 files reviewed, 8 unresolved discussions (waiting on @mariaFernando)
portal/autoconfig.py, line 107 at r1 (raw file):
"django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.auth.middleware.SessionAuthenticationMiddleware", "portal.middleware.django_online_status.online_status.middleware.OnlineStatusMiddleware",
the folder structure here seems a bit redundant.... portal -> middleware -> .... -> middleware -> ...
as a note, if this changes, you need to make this change in deploy-appengine possibly also
portal/middleware/django_online_status/.hgignore, line 2 at r1 (raw file):
syntax: glob
we don't use mercurial so we don't need this here
portal/middleware/django_online_status/.hgtags, line 1 at r1 (raw file):
c14b815efd477f233cf57c7605c14773ab6f12d5 0_1_0
we don't use mercurial, delete this
portal/middleware/django_online_status/AUTHORS, line 1 at r1 (raw file):
Jakub Zalewski http://zalew.tumblr.com
delete this file
portal/middleware/django_online_status/README, line 1 at r1 (raw file):
========================
delete this
portal/middleware/django_online_status/setup.py, line 1 at r1 (raw file):
#!/usr/bin/env python
this doesn't need to be its own package, delete this
portal/middleware/django_online_status/UNLICENSE, line 1 at r1 (raw file):
This is free and unencumbered software released into the public domain.
delete this
portal/middleware/django_online_status/.hg/00changelog.i, line 0 at r1 (raw file):
delete the .hg folder please
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.
Reviewed 2 of 93 files at r1.
Reviewable status: 12 of 93 files reviewed, 13 unresolved discussions (waiting on @mariaFernando)
a discussion (no related file):
Can we have a more detailed description of the fix please? The middleware was already there, this PR should describe what was fixed in it
portal/middleware/django_online_status/online_status/middleware.py, line 15 at r1 (raw file):
class OnlineStatusMiddleware(MiddlewareMixin):
to make this a bit more futureproof, can we use the modern API for middleware here please?
portal/middleware/django_online_status/online_status/middleware.py, line 15 at r1 (raw file):
class OnlineStatusMiddleware(MiddlewareMixin):
Can we confirm that the behavioural differences between MIDDLEWARE
and MIDDLEWARE_CLASSES
do not affect the way this middleware works?
portal/middleware/django_online_status/online_status/models.py, line 0 at r1 (raw file):
afaik middleware do not need a models file, I would remove this
portal/middleware/django_online_status/online_status/status.py, line 96 at r1 (raw file):
def status_for_user(user): """Return status for user, duh?"""
Let's replace this with a more useful docstring
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.
Reviewable status: 12 of 93 files reviewed, 14 unresolved discussions (waiting on @mariaFernando)
a discussion (no related file):
@dent50cent are your docs changes in this PR?
portal/middleware/django_online_status/.hgignore, line 2 at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
Done. |
portal/middleware/django_online_status/.hgtags, line 1 at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
Done. |
portal/middleware/django_online_status/AUTHORS, line 1 at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
Done. |
portal/middleware/django_online_status/README, line 1 at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
Done. |
portal/middleware/django_online_status/setup.py, line 1 at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
Done. |
portal/middleware/django_online_status/UNLICENSE, line 1 at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
Done. |
portal/middleware/django_online_status/online_status/models.py, line at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
Done. |
portal/middleware/django_online_status/online_status/status.py, line 96 at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
Done. |
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.
Reviewable status: 12 of 94 files reviewed, 14 unresolved discussions (waiting on @mariaFernando and @mrniket)
portal/middleware/django_online_status/.hgignore, line 2 at r1 (raw file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
Done.
not done? perhaps you haven't pushed?
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.
Reviewable status: 12 of 94 files reviewed, 14 unresolved discussions (waiting on @mariaFernando and @mrniket)
portal/middleware/django_online_status/.hgtags, line 1 at r1 (raw file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
Done.
not done?
a discussion (no related file): Previously, mrniket (Niket Shah) wrote…
Is the description more fitting now, or should I go more in detail? |
portal/autoconfig.py, line 107 at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
The folder structure is now portal/middleware/django_online_status. Should I rename middleware.py, too? |
portal/middleware/django_online_status/.hgignore, line 2 at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
I hadn't pushed, but it seems like the deletion didn't get properly pushed..? |
portal/middleware/django_online_status/.hg/00changelog.i, line at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
Done. |
a discussion (no related file): Previously, mrniket (Niket Shah) wrote…
They are |
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.
Reviewed 1 of 2 files at r2.
Reviewable status: 2 of 20 files reviewed, 16 unresolved discussions (waiting on @dent50cent, @mariaFernando, and @mrniket)
docs/online_status_middleware.md, line 9 at r4 (raw file):
There are couple of template tags to access this information to help make use of this functionality. Also, this middleware contains a couple of view/urls by default, the only one that should exist is the `/test` url as one of the others lists every single user currently online for everyone to see which may pose a security risk, and the other is an example which probably shouldn't exist in a production enviroment, if these are present in your project (or are not ignored) please make sure they don't end up in production.
I think the views and urls won't be there in the end
portal/autoconfig.py, line 107 at r1 (raw file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
The folder structure is now portal/middleware/django_online_status. Should I rename middleware.py, too?
well, if you use the __init.py__
in django_online_status to expose the OnlineStatusMiddleware there, you don't need to specify the middleware.py part in the import path
portal/autoconfig.py, line 107 at r1 (raw file):
"django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.auth.middleware.SessionAuthenticationMiddleware", "portal.middleware.django_online_status.online_status.middleware.OnlineStatusMiddleware",
also, this doesn't make a lot of difference, but we don't need the django_
prefix here if we are already in a django project, right?
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.
Reviewed 11 of 93 files at r1, 32 of 38 files at r3, 42 of 45 files at r4.
Reviewable status: 17 of 20 files reviewed, 19 unresolved discussions (waiting on @dent50cent, @mariaFernando, and @mrniket)
portal/middleware/django_online_status/.hg/undo.bookmarks, line 0 at r4 (raw file):
this file looks to still be present?
portal/middleware/django_online_status/.hg/store/phaseroots, line 0 at r4 (raw file):
this file seems to still be present?
portal/middleware/django_online_status/.hg/store/undo.phaseroots, line 0 at r4 (raw file):
this file seems to still be present?
portal/middleware/django_online_status/.hg/wcache/checkisexec, line 0 at r4 (raw file):
this file seems to still be there?
portal/middleware/django_online_status/.hg/wcache/checklink-target, line 0 at r4 (raw file):
this file seems to still be there?
portal/middleware/django_online_status/build/lib/online_status/models.py, line 0 at r4 (raw file):
this file seems to still be there?
portal/middleware/django_online_status/build/lib/online_status/templatetags/init.py, line 0 at r4 (raw file):
this file seems to still be there?
portal/middleware/django_online_status/online_status/templatetags/init.py, line 0 at r4 (raw file):
template tags should probably not be in the middleware folder right?
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.
Reviewable status: 17 of 20 files reviewed, 19 unresolved discussions (waiting on @mariaFernando and @mrniket)
portal/tests/test_online_status.py, line 91 at r4 (raw file):
self.client.get(reverse("dashboard")) useronline = cache.get(status.CACHE_PREFIX_USER % self.user1.pk)
maybe it's best to test user2 here as user1 is already testing in setup_conditions
?
portal/middleware/django_online_status/online_status/middleware.py, line 15 at r1 (raw file): Previously, mrniket (Niket Shah) wrote…
We've checked it, it won't affect this middleware in particular |
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.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @mariaFernando and @mrniket)
a discussion (no related file):
Previously, mrniket (Niket Shah) wrote…
just wondering why the idle status was removed?
We came to the conclusion it wasn't needed and is unlikely to be needed in the future for this functionality (if it is, it's not hard to implement again)
portal/autoconfig.py, line 107 at r6 (raw file):
Previously, mrniket (Niket Shah) wrote…
can we have a PR ready to change this in deploy appengine too? https://github.com/ocadotechnology/codeforlife-deploy-appengine/blob/master/django_site/settings.py#L62
Will do
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.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @mariaFernando)
a discussion (no related file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
We came to the conclusion it wasn't needed and is unlikely to be needed in the future for this functionality (if it is, it's not hard to implement again)
I don't remember this conversation... normally decisions to remove or add functionality go through the PO
I would add it back, we don't know to impact of that change and it shouldn't be in a bug fix PR. My guess is that it could be useful for teachers monitoring their classes.
a discussion (no related file): Previously, mrniket (Niket Shah) wrote…
You're right, I'll add it back in. What should the offline and idle times be, 5 and 10 minutes like the original functionality? |
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.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @mariaFernando and @mrniket)
portal/tests/test_online_status.py, line 51 at r6 (raw file):
Previously, mrniket (Niket Shah) wrote…
can we make the sleep time as small as possible please
The override wasn't working properly, fixed now but it still seems to need rounded seconds, especially with the idle/offline distinction
portal/tests/test_online_status.py, line 100 at r6 (raw file):
Previously, mrniket (Niket Shah) wrote…
if we manually change
user1.seen
then we can probably test this without a sleep
the set_active method sets seen to datetime.now() so it can't be manually set
removed offline users from list of online users, which wasn't there before and might have caused the cache overflow. Online, offline and idle tests have been rewritten
portal/middleware/online_status/status.py, line 92 at r6 (raw file): Previously, mrniket (Niket Shah) wrote…
Removed that function |
portal/autoconfig.py, line 107 at r6 (raw file): Previously, mariaFernando (Maria Mafalda Fernando) wrote…
Done. |
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.
Reviewed 2 of 3 files at r7.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @mrniket)
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.
Dismissed @mrniket from 2 discussions.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @mrniket)
portal/autoconfig.py, line 107 at r6 (raw file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
Done.
Resolving.
portal/middleware/online_status/status.py, line 92 at r6 (raw file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
Removed that function
Resolving.
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.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @mariaFernando and @mrniket)
a discussion (no related file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
You're right, I'll add it back in. What should the offline and idle times be, 5 and 10 minutes like the original functionality?
sounds good 👍 thanks
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.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @mariaFernando)
portal/tests/test_online_status.py, line 100 at r6 (raw file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
the set_active method sets seen to datetime.now() so it can't be manually set
there are two ways around this, you can either mock/patch the datetime.now() method for the first request or you can access the user object from the cache (which I believe you do below) and set the seen field on it
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.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @mariaFernando)
portal/tests/test_online_status.py, line 51 at r6 (raw file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
The override wasn't working properly, fixed now but it still seems to need rounded seconds, especially with the idle/offline distinction
sorry, what do you mean by rounded seconds?
portal/tests/test_online_status.py, line 48 at r7 (raw file):
from portal.middleware.online_status import status status.TIME_OFFLINE = 3
having this here will on the module level mean that these settings could be used elsewhere. We need to find a way of doing this only for the TestCase below
portal/tests/test_online_status.py, line 51 at r6 (raw file): Previously, mrniket (Niket Shah) wrote…
I used fractional values and it doesn't detect the difference between idle and offline times, possibly because of this line: seconds = (datetime.now() - online_status.seen).seconds . I might be wrong, though |
portal/tests/test_online_status.py, line 100 at r6 (raw file): Previously, mrniket (Niket Shah) wrote…
Accessing the user object from the cache won't work, since it's the request that simultaneously sets the status and seen to datetime.now(), so setting it manually would always be overriden when the status is set. But I'll look into that first option |
portal/tests/test_online_status.py, line 48 at r7 (raw file): Previously, mrniket (Niket Shah) wrote…
Do you have any suggestion? override-settings doesn't seem to work. I'll keep looking for a solution and we can discuss it if I can't find one |
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.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @mariaFernando and @mrniket)
portal/tests/test_online_status.py, line 48 at r7 (raw file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
Do you have any suggestion? override-settings doesn't seem to work. I'll keep looking for a solution and we can discuss it if I can't find one
let's discuss on Monday
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.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @mariaFernando)
portal/tests/test_online_status.py, line 100 at r6 (raw file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
Accessing the user object from the cache won't work, since it's the request that simultaneously sets the status and seen to datetime.now(), so setting it manually would always be overriden when the status is set. But I'll look into that first option
👍
no more sleep :D
a discussion (no related file): Previously, mrniket (Niket Shah) wrote…
Done. |
portal/tests/test_online_status.py, line 48 at r7 (raw file): Previously, mrniket (Niket Shah) wrote…
Used mock patch, seems to work well and the sleep and setting override aren't needed anymore |
portal/tests/test_online_status.py, line 100 at r6 (raw file): Previously, mrniket (Niket Shah) wrote…
Done. |
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.
Reviewed 1 of 3 files at r8.
Reviewable status: 7 of 8 files reviewed, 3 unresolved discussions (waiting on @faucomte97 and @mrniket)
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.
Reviewed 1 of 3 files at r8.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @mariaFernando)
portal/tests/test_online_status.py, line 48 at r7 (raw file):
Previously, mariaFernando (Maria Mafalda Fernando) wrote…
Used mock patch, seems to work well and the sleep and setting override aren't needed anymore
great 👍
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.
Reviewable status: complete! all files reviewed, all discussions resolved
Replaced existing Django Online Status Middleware with the one cloned here . Integrated the code with the project and existing tests.
The code that was there before seemed to be failing to remove users from the online user list, causing an error as the cache was set to hold more than its data size limit of 1 MB.
Documentation was added.