comparison rhodecode/controllers/summary.py @ 1038:5554aa9c2480 beta

another major code rafactor, reimplemented (almost from scratch) the way caching works, Should be solid rock for now. Some code optymizations on scmModel.get() to make it don't load unneded things. Changed db cache to file that should also reduce memory size
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 13 Feb 2011 00:29:31 +0100
parents 72f008ed9b18
children 3fc9183e05dd
comparison
equal deleted inserted replaced
1037:b1d6478d4561 1038:5554aa9c2480
62 def __before__(self): 62 def __before__(self):
63 super(SummaryController, self).__before__() 63 super(SummaryController, self).__before__()
64 64
65 def index(self): 65 def index(self):
66 scm_model = ScmModel() 66 scm_model = ScmModel()
67 c.repo_info = scm_model.get_repo(c.repo_name) 67 c.repo, dbrepo = scm_model.get(c.repo_name)
68 c.dbrepo = dbrepo
68 c.following = scm_model.is_following_repo(c.repo_name, 69 c.following = scm_model.is_following_repo(c.repo_name,
69 c.rhodecode_user.user_id) 70 c.rhodecode_user.user_id)
70 def url_generator(**kw): 71 def url_generator(**kw):
71 return url('shortlog_home', repo_name=c.repo_name, **kw) 72 return url('shortlog_home', repo_name=c.repo_name, **kw)
72 73
73 c.repo_changesets = Page(c.repo_info, page=1, items_per_page=10, 74 c.repo_changesets = Page(c.repo, page=1, items_per_page=10,
74 url=url_generator) 75 url=url_generator)
75 76
76 e = request.environ 77 e = request.environ
77 78
78 if self.rhodecode_user.username == 'default': 79 if self.rhodecode_user.username == 'default':
90 'host':e.get('HTTP_HOST'), 91 'host':e.get('HTTP_HOST'),
91 'prefix':e.get('SCRIPT_NAME'), 92 'prefix':e.get('SCRIPT_NAME'),
92 'repo_name':c.repo_name, } 93 'repo_name':c.repo_name, }
93 c.clone_repo_url = uri 94 c.clone_repo_url = uri
94 c.repo_tags = OrderedDict() 95 c.repo_tags = OrderedDict()
95 for name, hash in c.repo_info.tags.items()[:10]: 96 for name, hash in c.repo.tags.items()[:10]:
96 try: 97 try:
97 c.repo_tags[name] = c.repo_info.get_changeset(hash) 98 c.repo_tags[name] = c.repo.get_changeset(hash)
98 except ChangesetError: 99 except ChangesetError:
99 c.repo_tags[name] = EmptyChangeset(hash) 100 c.repo_tags[name] = EmptyChangeset(hash)
100 101
101 c.repo_branches = OrderedDict() 102 c.repo_branches = OrderedDict()
102 for name, hash in c.repo_info.branches.items()[:10]: 103 for name, hash in c.repo.branches.items()[:10]:
103 try: 104 try:
104 c.repo_branches[name] = c.repo_info.get_changeset(hash) 105 c.repo_branches[name] = c.repo.get_changeset(hash)
105 except ChangesetError: 106 except ChangesetError:
106 c.repo_branches[name] = EmptyChangeset(hash) 107 c.repo_branches[name] = EmptyChangeset(hash)
107 108
108 td = date.today() + timedelta(days=1) 109 td = date.today() + timedelta(days=1)
109 td_1m = td - timedelta(days=calendar.mdays[td.month]) 110 td_1m = td - timedelta(days=calendar.mdays[td.month])
111 112
112 ts_min_m = mktime(td_1m.timetuple()) 113 ts_min_m = mktime(td_1m.timetuple())
113 ts_min_y = mktime(td_1y.timetuple()) 114 ts_min_y = mktime(td_1y.timetuple())
114 ts_max_y = mktime(td.timetuple()) 115 ts_max_y = mktime(td.timetuple())
115 116
116 if c.repo_info.dbrepo.enable_statistics: 117 if dbrepo.enable_statistics:
117 c.no_data_msg = _('No data loaded yet') 118 c.no_data_msg = _('No data loaded yet')
118 run_task(get_commits_stats, c.repo_info.name, ts_min_y, ts_max_y) 119 run_task(get_commits_stats, c.repo.name, ts_min_y, ts_max_y)
119 else: 120 else:
120 c.no_data_msg = _('Statistics update are disabled for this repository') 121 c.no_data_msg = _('Statistics update are disabled for this repository')
121 c.ts_min = ts_min_m 122 c.ts_min = ts_min_m
122 c.ts_max = ts_max_y 123 c.ts_max = ts_max_y
123 124
124 stats = self.sa.query(Statistics)\ 125 stats = self.sa.query(Statistics)\
125 .filter(Statistics.repository == c.repo_info.dbrepo)\ 126 .filter(Statistics.repository == dbrepo)\
126 .scalar() 127 .scalar()
127 128
128 129
129 if stats and stats.languages: 130 if stats and stats.languages:
130 c.no_data = False is c.repo_info.dbrepo.enable_statistics 131 c.no_data = False is dbrepo.enable_statistics
131 lang_stats = json.loads(stats.languages) 132 lang_stats = json.loads(stats.languages)
132 c.commit_data = stats.commit_activity 133 c.commit_data = stats.commit_activity
133 c.overview_data = stats.commit_activity_combined 134 c.overview_data = stats.commit_activity_combined
134 c.trending_languages = json.dumps(OrderedDict( 135 c.trending_languages = json.dumps(OrderedDict(
135 sorted(lang_stats.items(), reverse=True, 136 sorted(lang_stats.items(), reverse=True,
140 c.commit_data = json.dumps({}) 141 c.commit_data = json.dumps({})
141 c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 10] ]) 142 c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 10] ])
142 c.trending_languages = json.dumps({}) 143 c.trending_languages = json.dumps({})
143 c.no_data = True 144 c.no_data = True
144 145
145 c.enable_downloads = c.repo_info.dbrepo.enable_downloads 146 c.enable_downloads = dbrepo.enable_downloads
146 if c.enable_downloads: 147 if c.enable_downloads:
147 c.download_options = self._get_download_links(c.repo_info) 148 c.download_options = self._get_download_links(c.repo)
148 149
149 return render('summary/summary.html') 150 return render('summary/summary.html')
150 151
151 152
152 153