diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-05-25 19:35:48 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-05-25 19:35:48 -0400 |
commit | f8e3c3b96277dc66a0d378b5d825bf1837daf1ee (patch) | |
tree | a14af7bf10f170938de28c316c1271d247e16d3c /feeds.py | |
parent | 6e6f3c906c59360c792d3387eb0662f7f0f3eddc (diff) | |
parent | 824bd93116c4c0a48d7112ae0bceb46e70851df5 (diff) |
Merge branch 'master-nomake'
Diffstat (limited to 'feeds.py')
-rw-r--r-- | feeds.py | 40 |
1 files changed, 36 insertions, 4 deletions
@@ -15,6 +15,22 @@ from news.models import News from releng.models import Release +class BatchWritesWrapper(object): + def __init__(self, outfile, chunks=20): + self.outfile = outfile + self.chunks = chunks + self.buf = [] + def write(self, s): + buf = self.buf + buf.append(s) + if len(buf) >= self.chunks: + self.outfile.write(''.join(buf)) + self.buf = [] + def flush(self): + self.outfile.write(''.join(self.buf)) + self.outfile.flush() + + class GuidNotPermalinkFeed(Rss201rev2Feed): @staticmethod def check_for_unique_id(f): @@ -27,13 +43,26 @@ class GuidNotPermalinkFeed(Rss201rev2Feed): return wrapper def write_items(self, handler): - # Totally disgusting. Monkey-patch the hander so if it sees a - # 'unique-id' field come through, add an isPermalink="false" attribute. - # Workaround for http://code.djangoproject.com/ticket/9800 + ''' + Totally disgusting. Monkey-patch the handler so if it sees a + 'unique-id' field come through, add an isPermalink="false" attribute. + Workaround for http://code.djangoproject.com/ticket/9800 + ''' handler.addQuickElement = self.check_for_unique_id( handler.addQuickElement) super(GuidNotPermalinkFeed, self).write_items(handler) + def write(self, outfile, encoding): + ''' + Batch the underlying 'write' calls on the outfile because Python's + default saxutils XmlGenerator is a POS that insists on unbuffered + write/flush calls. This sucks when it is making 1-byte calls to write + '>' closing tags and over 1600 write calls in our package feed. + ''' + wrapper = BatchWritesWrapper(outfile) + super(GuidNotPermalinkFeed, self).write(wrapper, encoding) + wrapper.flush() + def package_etag(request, *args, **kwargs): latest = retrieve_latest(Package) @@ -195,7 +224,10 @@ class ReleaseFeed(Feed): return "%s://%s/%s.torrent" % (proto, domain, item.iso_url()) def item_enclosure_length(self, item): - return item.file_size or "" + if item.torrent_data: + torrent = item.torrent() + return torrent['file_length'] or "" + return "" item_enclosure_mime_type = 'application/x-bittorrent' |