mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Deleting old shared stories by free users no longer using the service.
This commit is contained in:
parent
969113c52e
commit
48949f22a7
3 changed files with 50 additions and 8 deletions
|
@ -2183,7 +2183,7 @@ class MStarredStory(mongo.Document):
|
||||||
return stories
|
return stories
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def trim_old_stories(cls, stories=10, days=60, dryrun=False):
|
def trim_old_stories(cls, stories=10, days=90, dryrun=False):
|
||||||
print " ---> Fetching starred story counts..."
|
print " ---> Fetching starred story counts..."
|
||||||
stats = settings.MONGODB.newsblur.starred_stories.aggregate([{
|
stats = settings.MONGODB.newsblur.starred_stories.aggregate([{
|
||||||
"$group": {
|
"$group": {
|
||||||
|
|
|
@ -1500,7 +1500,49 @@ class MSharedStory(mongo.Document):
|
||||||
self.remove_from_redis()
|
self.remove_from_redis()
|
||||||
|
|
||||||
super(MSharedStory, self).delete(*args, **kwargs)
|
super(MSharedStory, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def trim_old_stories(cls, stories=10, days=90, dryrun=False):
|
||||||
|
print " ---> Fetching shared story counts..."
|
||||||
|
stats = settings.MONGODB.newsblur.shared_stories.aggregate([{
|
||||||
|
"$group": {
|
||||||
|
"_id": "$user_id",
|
||||||
|
"stories": {"$sum": 1},
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
"$match": {
|
||||||
|
"stories": {"$gte": stories}
|
||||||
|
},
|
||||||
|
}])
|
||||||
|
month_ago = datetime.datetime.now() - datetime.timedelta(days=days)
|
||||||
|
user_ids = stats['result']
|
||||||
|
user_ids = sorted(user_ids, key=lambda x:x['stories'], reverse=True)
|
||||||
|
print " ---> Found %s users with more than %s starred stories" % (len(user_ids), stories)
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
for stat in user_ids:
|
||||||
|
try:
|
||||||
|
user = User.objects.select_related('profile').get(pk=stat['_id'])
|
||||||
|
except User.DoesNotExist:
|
||||||
|
user = None
|
||||||
|
|
||||||
|
if user and (user.profile.is_premium or user.profile.last_seen_on > month_ago):
|
||||||
|
continue
|
||||||
|
|
||||||
|
total += stat['stories']
|
||||||
|
username = "%s (%s)" % (user and user.username or " - ", stat['_id'])
|
||||||
|
print " ---> %19.19s: %-20.20s %s stories" % (user and user.profile.last_seen_on or "Deleted",
|
||||||
|
username,
|
||||||
|
stat['stories'])
|
||||||
|
if not dryrun and stat['_id']:
|
||||||
|
cls.objects.filter(user_id=stat['_id']).delete()
|
||||||
|
elif not dryrun and stat['_id'] == 0:
|
||||||
|
print " ---> Deleting unshared stories (user_id = 0)"
|
||||||
|
cls.objects.filter(user_id=stat['_id']).delete()
|
||||||
|
|
||||||
|
|
||||||
|
print " ---> Deleted %s stories in total." % total
|
||||||
|
|
||||||
def unshare_story(self):
|
def unshare_story(self):
|
||||||
socialsubs = MSocialSubscription.objects.filter(subscription_user_id=self.user_id,
|
socialsubs = MSocialSubscription.objects.filter(subscription_user_id=self.user_id,
|
||||||
needs_unread_recalc=False)
|
needs_unread_recalc=False)
|
||||||
|
|
12
fabfile.py
vendored
12
fabfile.py
vendored
|
@ -823,12 +823,12 @@ def setup_db_firewall():
|
||||||
))
|
))
|
||||||
|
|
||||||
# EC2
|
# EC2
|
||||||
for host in set(env.roledefs['ec2task']):
|
# for host in set(env.roledefs['ec2task']):
|
||||||
ip = re.search('ec2-(\d+-\d+-\d+-\d+)', host).group(1).replace('-', '.')
|
# ip = re.search('ec2-(\d+-\d+-\d+-\d+)', host).group(1).replace('-', '.')
|
||||||
sudo('ufw allow proto tcp from %s to any port %s' % (
|
# sudo('ufw allow proto tcp from %s to any port %s' % (
|
||||||
ip,
|
# ip,
|
||||||
','.join(map(str, ports))
|
# ','.join(map(str, ports))
|
||||||
))
|
# ))
|
||||||
|
|
||||||
sudo('ufw --force enable')
|
sudo('ufw --force enable')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue