mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-05 18:34:52 +00:00
Purge related URLs from varnish when a new item is fetched from RSS
Fixes #95
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from pgweb.util.bases import PgModel
|
||||
from pgweb.util.misc import varnish_purge
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
@ -86,6 +87,11 @@ class Organisation(PgModel, models.Model):
|
||||
class ImportedRSSFeed(models.Model):
|
||||
internalname = models.CharField(max_length=32, null=False, blank=False, unique=True)
|
||||
url = models.URLField(null=False, blank=False)
|
||||
purgepattern = models.CharField(max_length=512, null=False, blank=True, help_text="NOTE! Pattern will be automatically anchored with ^ at the beginning, but you must lead with a slash in most cases - and don't forget to include the trailing $ in most cases")
|
||||
|
||||
def purge_related(self):
|
||||
if self.purgepattern:
|
||||
varnish_purge(self.purgepattern)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.internalname
|
||||
|
@ -32,6 +32,7 @@ for importfeed in ImportedRSSFeed.objects.all():
|
||||
raise Exception('Feed load error with no exception!')
|
||||
if feed.status != 200:
|
||||
raise Exception('Feed returned status %s' % feed.status)
|
||||
fetchedsomething = False
|
||||
for entry in feed.entries:
|
||||
try:
|
||||
item = ImportedRSSItem.objects.get(feed=importfeed, url=entry.link)
|
||||
@ -42,6 +43,9 @@ for importfeed in ImportedRSSFeed.objects.all():
|
||||
posttime=datetime.strptime(entry.date, "%a, %d %b %Y %H:%M:%S %Z"),
|
||||
)
|
||||
item.save()
|
||||
fetchedsomething = True
|
||||
if fetchedsomething:
|
||||
importfeed.purge_related()
|
||||
transaction.commit()
|
||||
except Exception, e:
|
||||
print "Failed to load %s: %s" % (importfeed, e)
|
||||
|
Reference in New Issue
Block a user