##// END OF EJS Templates
drastic speed improvment in feed generation (was using old method)
marcink -
r507:f420e86d default
parent child Browse files
Show More
@@ -1,81 +1,80
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3 # feed controller for pylons
3 # feed controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5
5
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
9 # of the License or (at your opinion) any later version of the license.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
19 # MA 02110-1301, USA.
20 """
20 """
21 Created on April 23, 2010
21 Created on April 23, 2010
22 feed controller for pylons
22 feed controller for pylons
23 @author: marcink
23 @author: marcink
24 """
24 """
25 from pylons import tmpl_context as c, url, response
25 from pylons import tmpl_context as c, url, response
26 from pylons_app.lib.base import BaseController, render
26 from pylons_app.lib.base import BaseController, render
27 from pylons_app.model.hg_model import _full_changelog_cached
27 from pylons_app.model.hg_model import HgModel
28 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
28 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
29 import logging
29 import logging
30 log = logging.getLogger(__name__)
30 log = logging.getLogger(__name__)
31
31
32 class FeedController(BaseController):
32 class FeedController(BaseController):
33
33
34 #secure it or not ?
34 #secure it or not ?
35 def __before__(self):
35 def __before__(self):
36 super(FeedController, self).__before__()
36 super(FeedController, self).__before__()
37 #common values for feeds
37 #common values for feeds
38 self.description = 'Changes on %s repository'
38 self.description = 'Changes on %s repository'
39 self.title = "%s feed"
39 self.title = "%s feed"
40 self.language = 'en-us'
40 self.language = 'en-us'
41 self.ttl = "5"
41 self.ttl = "5"
42 self.feed_nr = 10
42 self.feed_nr = 10
43
43
44 def atom(self, repo_name):
44 def atom(self, repo_name):
45 """Produce an atom-1.0 feed via feedgenerator module"""
45 """Produce an atom-1.0 feed via feedgenerator module"""
46 feed = Atom1Feed(title=self.title % repo_name,
46 feed = Atom1Feed(title=self.title % repo_name,
47 link=url('summary_home', repo_name=repo_name, qualified=True),
47 link=url('summary_home', repo_name=repo_name, qualified=True),
48 description=self.description % repo_name,
48 description=self.description % repo_name,
49 language=self.language,
49 language=self.language,
50 ttl=self.ttl)
50 ttl=self.ttl)
51
51
52 changesets = HgModel().get_repo(repo_name)
52
53
53 for cnt, cs in enumerate(_full_changelog_cached(repo_name)):
54 for cs in changesets[:self.feed_nr]:
54 if cnt > self.feed_nr:
55 break
56 feed.add_item(title=cs.message,
55 feed.add_item(title=cs.message,
57 link=url('changeset_home', repo_name=repo_name,
56 link=url('changeset_home', repo_name=repo_name,
58 revision=cs.raw_id, qualified=True),
57 revision=cs.raw_id, qualified=True),
59 description=str(cs.date))
58 description=str(cs.date))
60
59
61 response.content_type = feed.mime_type
60 response.content_type = feed.mime_type
62 return feed.writeString('utf-8')
61 return feed.writeString('utf-8')
63
62
64
63
65 def rss(self, repo_name):
64 def rss(self, repo_name):
66 """Produce an rss2 feed via feedgenerator module"""
65 """Produce an rss2 feed via feedgenerator module"""
67 feed = Rss201rev2Feed(title=self.title % repo_name,
66 feed = Rss201rev2Feed(title=self.title % repo_name,
68 link=url('summary_home', repo_name=repo_name, qualified=True),
67 link=url('summary_home', repo_name=repo_name, qualified=True),
69 description=self.description % repo_name,
68 description=self.description % repo_name,
70 language=self.language,
69 language=self.language,
71 ttl=self.ttl)
70 ttl=self.ttl)
72
71
73 for cnt, cs in enumerate(_full_changelog_cached(repo_name)):
72 changesets = HgModel().get_repo(repo_name)
74 if cnt > self.feed_nr:
73 for cs in changesets[:self.feed_nr]:
75 break
76 feed.add_item(title=cs.message,
74 feed.add_item(title=cs.message,
77 link=url('changeset_home', repo_name=repo_name, revision=cs.raw_id, qualified=True),
75 link=url('changeset_home', repo_name=repo_name,
76 revision=cs.raw_id, qualified=True),
78 description=str(cs.date))
77 description=str(cs.date))
79
78
80 response.content_type = feed.mime_type
79 response.content_type = feed.mime_type
81 return feed.writeString('utf-8')
80 return feed.writeString('utf-8')
General Comments 0
You need to be logged in to leave comments. Login now