mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Changing resoltuion of feed counts munin to 12 hours to spare the database.
This commit is contained in:
parent
b05ddbec87
commit
66ca1d7628
2 changed files with 39 additions and 8 deletions
|
@ -12,6 +12,7 @@ from utils import db_functions
|
|||
class MStatistics(mongo.Document):
|
||||
key = mongo.StringField(unique=True)
|
||||
value = mongo.DynamicField()
|
||||
expiration_date = mongo.DateTimeField(null=True)
|
||||
|
||||
meta = {
|
||||
'collection': 'statistics',
|
||||
|
@ -27,15 +28,19 @@ class MStatistics(mongo.Document):
|
|||
obj = cls.objects.filter(key=key).first()
|
||||
if not obj:
|
||||
return default
|
||||
if obj.expiration_date and obj.expiration_date < datetime.datetime.now():
|
||||
return default
|
||||
return obj.value
|
||||
|
||||
@classmethod
|
||||
def set(cls, key, value):
|
||||
def set(cls, key, value, expiration_sec=None):
|
||||
try:
|
||||
obj = cls.objects.get(key=key)
|
||||
except cls.DoesNotExist:
|
||||
obj = cls.objects.create(key=key)
|
||||
obj.value = value
|
||||
if expiration_sec:
|
||||
obj.expiration_date = datetime.datetime.now() + datetime.timedelta(seconds=expiration_sec)
|
||||
obj.save()
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -23,16 +23,42 @@ class NBMuninGraph(MuninGraph):
|
|||
from apps.rss_feeds.models import Feed, DuplicateFeed
|
||||
from apps.push.models import PushSubscription
|
||||
from django.conf import settings
|
||||
|
||||
from apps.statistics.models import MStatistics
|
||||
|
||||
exception_feeds = MStatistics.get('munin:exception_feeds')
|
||||
if not exception_feeds:
|
||||
exception_feeds = Feed.objects.filter(has_feed_exception=True).count()
|
||||
MStatistics.set('munin:exception_feeds', exception_feeds, 60*60*12)
|
||||
|
||||
exception_pages = MStatistics.get('munin:exception_pages')
|
||||
if not exception_pages:
|
||||
exception_pages = Feed.objects.filter(has_page_exception=True).count()
|
||||
MStatistics.set('munin:exception_pages', exception_pages, 60*60*12)
|
||||
|
||||
duplicate_feeds = MStatistics.get('munin:duplicate_feeds')
|
||||
if not duplicate_feeds:
|
||||
duplicate_feeds = DuplicateFeed.objects.count()
|
||||
MStatistics.set('munin:duplicate_feeds', duplicate_feeds, 60*60*12)
|
||||
|
||||
active_feeds = MStatistics.get('munin:active_feeds')
|
||||
if not active_feeds:
|
||||
active_feeds = Feed.objects.filter(active_subscribers__gt=0).count()
|
||||
MStatistics.set('munin:active_feeds', active_feeds, 60*60*12)
|
||||
|
||||
push_feeds = MStatistics.get('munin:push_feeds')
|
||||
if not push_feeds:
|
||||
push_feeds = PushSubscription.objects.filter(verified=True).count()
|
||||
MStatistics.set('munin:push_feeds', push_feeds, 60*60*12)
|
||||
|
||||
r = redis.Redis(connection_pool=settings.REDIS_FEED_POOL)
|
||||
|
||||
|
||||
return {
|
||||
'scheduled_feeds': r.zcard('scheduled_updates'),
|
||||
'exception_feeds': Feed.objects.filter(has_feed_exception=True).count(),
|
||||
'exception_pages': Feed.objects.filter(has_page_exception=True).count(),
|
||||
'duplicate_feeds': DuplicateFeed.objects.count(),
|
||||
'active_feeds': Feed.objects.filter(active_subscribers__gt=0).count(),
|
||||
'push_feeds': PushSubscription.objects.filter(verified=True).count(),
|
||||
'exception_feeds': exception_feeds,
|
||||
'exception_pages': exception_pages,
|
||||
'duplicate_feeds': duplicate_feeds,
|
||||
'active_feeds': active_feeds,
|
||||
'push_feeds': push_feeds,
|
||||
}
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Reference in a new issue