-
Notifications
You must be signed in to change notification settings - Fork 19
Cleanup of old user accounts - Issue#218 #230
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.conf import settings | ||
from django.utils import timezone | ||
|
||
from celery import task | ||
|
||
from piplmesh.account import models as account_models | ||
from piplmesh.api import models as api_models | ||
|
||
@task.task | ||
def clean_inactive_lazy_users(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. But this we will have to REALLY improve. Now you read ALL users from database into Python just to know which users not to process. ;-) This is why databases support queries. So that you can limit what is transferred between database and Python to only what you are interested in at the end. So please create a MongoEngine query which will return only users which have not content and which are was more than the timeout inactive. Then run over them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been trying for few days now to find a way to build such query, but I had no luck. I literally checked all pages on google about this topic but I'm still stuck at the query. Any help would be much appreciated. I assume I have to use something like this: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this you can get all posts by the user at the same time as all posts with comments by the user: http://mongoengine-odm.readthedocs.org/en/latest/guide/querying.html#advanced-queries There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (But it is not necessary that it helps you here much.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But probably you will have to do a server-side query. Have you tried asking the question on StackOverflow? |
||
users_with_content = [] | ||
for post in api_models.Post.objects: | ||
users_with_content.append(post.author) | ||
for comment in post.comments: | ||
users_with_content.append(comment.author) | ||
users_with_content = list(set(users_with_content)) | ||
for user in account_models.User.objects: | ||
if not user.is_authenticated() and (timezone.now() - user.connection_last_unsubscribe).days >= settings.LAZY_USER_EXPIRATION and user not in users_with_content: | ||
user.delete() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,7 +203,9 @@ | |
), | ||
} | ||
|
||
CHECK_ONLINE_USERS_INTERVAL = 10 | ||
CHECK_ONLINE_USERS_INTERVAL = 10 # seconds | ||
CLEAN_INACTIVE_USERS_INTERVAL = 1 # days | ||
LAZY_USER_EXPIRATION = 30 # days | ||
|
||
CELERY_RESULT_BACKEND = 'mongodb' | ||
CELERY_MONGODB_BACKEND_SETTINGS = { | ||
|
@@ -221,6 +223,7 @@ | |
BROKER_VHOST = 'celery' | ||
|
||
CELERY_IMPORTS = ( | ||
'piplmesh.account.tasks', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Order alphabetically. |
||
'piplmesh.frontend.tasks', | ||
) | ||
|
||
|
@@ -230,6 +233,11 @@ | |
'schedule': datetime.timedelta(seconds=CHECK_ONLINE_USERS_INTERVAL), | ||
'args': (), | ||
}, | ||
'clean_inactive_lazy_users': { | ||
'task': 'piplmesh.account.tasks.clean_inactive_lazy_users', | ||
'schedule': datetime.timedelta(days=CLEAN_INACTIVE_USERS_INTERVAL), | ||
'args': (), | ||
}, | ||
} | ||
|
||
# A sample logging configuration. The only tangible logging | ||
|
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.
base
is not used?