annotate rhodecode/model/scm.py @ 792:4c16ed1eb699 beta

fixed bug introduced in latest commit
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 29 Nov 2010 22:40:54 +0100
parents 06a98912325c
children bb35ad076e2f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
1 # -*- coding: utf-8 -*-
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
2 """
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
3 package.rhodecode.model.scm
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
4 ~~~~~~~~~~~~~~
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
5
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
6 scm model for RhodeCode
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
7 :created_on: Apr 9, 2010
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
8 :author: marcink
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
9 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
10 :license: GPLv3, see COPYING for more details.
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
11 """
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
12 # This program is free software; you can redistribute it and/or
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
13 # modify it under the terms of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
14 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
15 # of the License or (at your opinion) any later version of the license.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
16 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
17 # This program is distributed in the hope that it will be useful,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
20 # GNU General Public License for more details.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
21 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
22 # You should have received a copy of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
23 # along with this program; if not, write to the Free Software
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
25 # MA 02110-1301, USA.
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
26
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
27 import os
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
28 import time
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
29 import traceback
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
30 import logging
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
31
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
32 from vcs import get_backend
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
33 from vcs.utils.helpers import get_scm
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
34 from vcs.exceptions import RepositoryError, VCSError
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
35 from vcs.utils.lazy import LazyProperty
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
36
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
37 from mercurial import ui
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
38
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
39 from beaker.cache import cache_region, region_invalidate
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
40
710
e2f3c8e6939d Disable git support due to large problems with dulwich.
Marcin Kuzminski <marcin@python-works.com>
parents: 693
diff changeset
41 from rhodecode import BACKENDS
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
42 from rhodecode.lib import helpers as h
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
43 from rhodecode.lib.auth import HasRepoPermissionAny
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
44 from rhodecode.lib.utils import get_repos, make_ui, action_logger
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 747
diff changeset
45 from rhodecode.model import BaseModel
758
6a31e64acabd code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 757
diff changeset
46 from rhodecode.model.user import UserModel
6a31e64acabd code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 757
diff changeset
47
6a31e64acabd code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 757
diff changeset
48 from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \
784
30d3161c6683 Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 767
diff changeset
49 UserFollowing, UserLog
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
50 from rhodecode.model.caching_query import FromCache
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
51
535
72778dda34cf some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents: 531
diff changeset
52 from sqlalchemy.orm import joinedload
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
53 from sqlalchemy.orm.session import make_transient
758
6a31e64acabd code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 757
diff changeset
54 from sqlalchemy.exc import DatabaseError
633
fcf599cd3404 Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
55
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
56 log = logging.getLogger(__name__)
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
57
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
58
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
59 class UserTemp(object):
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
60 def __init__(self, user_id):
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
61 self.user_id = user_id
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
62 class RepoTemp(object):
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
63 def __init__(self, repo_id):
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
64 self.repo_id = repo_id
747
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
65
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 747
diff changeset
66 class ScmModel(BaseModel):
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
67 """
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
68 Mercurial Model
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
69 """
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
70
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
71 @LazyProperty
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
72 def repos_path(self):
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
73 """
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
74 Get's the repositories root path from database
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
75 """
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
76 q = self.sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one()
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
77
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
78 return q.ui_value
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
79
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
80 def repo_scan(self, repos_path, baseui):
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
81 """
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
82 Listing of repositories in given path. This path should not be a
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
83 repository itself. Return a dictionary of repository objects
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
84
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
85 :param repos_path: path to directory containing repositories
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
86 :param baseui
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
87 """
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
88 log.info('scanning for repositories in %s', repos_path)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
89
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
90 if not isinstance(baseui, ui.ui):
724
a9bc513a1fe3 fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents: 715
diff changeset
91 baseui = make_ui('db')
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
92 repos_list = {}
690
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
93
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
94 for name, path in get_repos(repos_path):
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
95 try:
248
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
96 if repos_list.has_key(name):
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
97 raise RepositoryError('Duplicate repository name %s '
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
98 'found in %s' % (name, path))
248
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
99 else:
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
100
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
101 klass = get_backend(path[0])
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
102
710
e2f3c8e6939d Disable git support due to large problems with dulwich.
Marcin Kuzminski <marcin@python-works.com>
parents: 693
diff changeset
103 if path[0] == 'hg' and path[0] in BACKENDS.keys():
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
104 repos_list[name] = klass(path[1], baseui=baseui)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
105
710
e2f3c8e6939d Disable git support due to large problems with dulwich.
Marcin Kuzminski <marcin@python-works.com>
parents: 693
diff changeset
106 if path[0] == 'git' and path[0] in BACKENDS.keys():
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
107 repos_list[name] = klass(path[1])
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
108 except OSError:
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
109 continue
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
110
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
111 return repos_list
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
112
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
113 def get_repos(self, all_repos=None):
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
114 """
690
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
115 Get all repos from db and for each repo create it's backend instance.
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
116 and fill that backed with information from database
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
117
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
118 :param all_repos: give specific repositories list, good for filtering
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
119 """
767
632b0761e617 bugfix, when user had no repos he would see all repos in my account, (correct commit)
Marcin Kuzminski <marcin@python-works.com>
parents: 758
diff changeset
120 if all_repos is None:
693
90ac3255c117 fixed sorting for repo switcher, fixed length for code stats
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
121 all_repos = self.sa.query(Repository)\
90ac3255c117 fixed sorting for repo switcher, fixed length for code stats
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
122 .order_by(Repository.repo_name).all()
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
123
791
06a98912325c fixed bug when invalidation was making to many queries when there was no list of invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 784
diff changeset
124 #get the repositories that should be invalidated
726
04c4e5f94cee cache list speed improvement
Marcin Kuzminski <marcin@python-works.com>
parents: 724
diff changeset
125 invalidation_list = [str(x.cache_key) for x in \
04c4e5f94cee cache list speed improvement
Marcin Kuzminski <marcin@python-works.com>
parents: 724
diff changeset
126 self.sa.query(CacheInvalidation.cache_key)\
04c4e5f94cee cache list speed improvement
Marcin Kuzminski <marcin@python-works.com>
parents: 724
diff changeset
127 .filter(CacheInvalidation.cache_active == False)\
04c4e5f94cee cache list speed improvement
Marcin Kuzminski <marcin@python-works.com>
parents: 724
diff changeset
128 .all()]
04c4e5f94cee cache list speed improvement
Marcin Kuzminski <marcin@python-works.com>
parents: 724
diff changeset
129
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
130 for r in all_repos:
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
131
726
04c4e5f94cee cache list speed improvement
Marcin Kuzminski <marcin@python-works.com>
parents: 724
diff changeset
132 repo = self.get(r.repo_name, invalidation_list)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
133
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
134 if repo is not None:
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
135 last_change = repo.last_change
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
136 tip = h.get_changeset_safe(repo, 'tip')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
137
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
138 tmp_d = {}
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
139 tmp_d['name'] = repo.name
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
140 tmp_d['name_sort'] = tmp_d['name'].lower()
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
141 tmp_d['description'] = repo.dbrepo.description
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
142 tmp_d['description_sort'] = tmp_d['description']
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
143 tmp_d['last_change'] = last_change
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
144 tmp_d['last_change_sort'] = time.mktime(last_change.timetuple())
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
145 tmp_d['tip'] = tip.raw_id
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
146 tmp_d['tip_sort'] = tip.revision
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
147 tmp_d['rev'] = tip.revision
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
148 tmp_d['contact'] = repo.dbrepo.user.full_contact
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
149 tmp_d['contact_sort'] = tmp_d['contact']
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
150 tmp_d['repo_archives'] = list(repo._get_archives())
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
151 tmp_d['last_msg'] = tip.message
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
152 tmp_d['repo'] = repo
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
153 yield tmp_d
74
cdf4fda66dd9 Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents: 73
diff changeset
154
cdf4fda66dd9 Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents: 73
diff changeset
155 def get_repo(self, repo_name):
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
156 return self.get(repo_name)
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
157
726
04c4e5f94cee cache list speed improvement
Marcin Kuzminski <marcin@python-works.com>
parents: 724
diff changeset
158 def get(self, repo_name, invalidation_list=None):
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
159 """
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
160 Get's repository from given name, creates BackendInstance and
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
161 propagates it's data from database with all additional information
791
06a98912325c fixed bug when invalidation was making to many queries when there was no list of invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 784
diff changeset
162
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
163 :param repo_name:
791
06a98912325c fixed bug when invalidation was making to many queries when there was no list of invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 784
diff changeset
164 :param invalidation_list: if a invalidation list is given the get
06a98912325c fixed bug when invalidation was making to many queries when there was no list of invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 784
diff changeset
165 method should not manually check if this repository needs
06a98912325c fixed bug when invalidation was making to many queries when there was no list of invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 784
diff changeset
166 invalidation and just invalidate the repositories in list
06a98912325c fixed bug when invalidation was making to many queries when there was no list of invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 784
diff changeset
167
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
168 """
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
169 if not HasRepoPermissionAny('repository.read', 'repository.write',
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
170 'repository.admin')(repo_name, 'get repo check'):
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
171 return
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
172
791
06a98912325c fixed bug when invalidation was making to many queries when there was no list of invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 784
diff changeset
173 #======================================================================
06a98912325c fixed bug when invalidation was making to many queries when there was no list of invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 784
diff changeset
174 # CACHE FUNCTION
06a98912325c fixed bug when invalidation was making to many queries when there was no list of invalidation
Marcin Kuzminski <marcin@python-works.com>
parents: 784
diff changeset
175 #======================================================================
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
176 @cache_region('long_term')
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
177 def _get_repo(repo_name):
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
178
690
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
179 repo_path = os.path.join(self.repos_path, repo_name)
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
180
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
181 try:
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
182 alias = get_scm(repo_path)[0]
690
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
183
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
184 log.debug('Creating instance of %s repository', alias)
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
185 backend = get_backend(alias)
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
186 except VCSError:
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
187 log.error(traceback.format_exc())
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
188 return
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
189
690
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
190 if alias == 'hg':
715
066af351c6d8 Fixed archivals by passing baseui to scm get method for hg.
Marcin Kuzminski <marcin@python-works.com>
parents: 710
diff changeset
191 from pylons import app_globals as g
066af351c6d8 Fixed archivals by passing baseui to scm get method for hg.
Marcin Kuzminski <marcin@python-works.com>
parents: 710
diff changeset
192 repo = backend(repo_path, create=False, baseui=g.baseui)
690
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
193 #skip hidden web repository
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
194 if repo._get_hidden():
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
195 return
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
196 else:
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
197 repo = backend(repo_path, create=False)
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
198
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
199 dbrepo = self.sa.query(Repository)\
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
200 .options(joinedload(Repository.fork))\
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
201 .options(joinedload(Repository.user))\
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
202 .filter(Repository.repo_name == repo_name)\
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
203 .scalar()
753
ee801aa6292c changes transient to expunge on cached repo instances, due to odd very rare problems with previos approach.
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
204
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
205 make_transient(dbrepo)
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
206 if dbrepo.user:
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
207 make_transient(dbrepo.user)
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
208 if dbrepo.fork:
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
209 make_transient(dbrepo.fork)
753
ee801aa6292c changes transient to expunge on cached repo instances, due to odd very rare problems with previos approach.
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
210
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
211 repo.dbrepo = dbrepo
535
72778dda34cf some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents: 531
diff changeset
212 return repo
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
213
792
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
214 pre_invalidate = True
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
215 if invalidation_list is not None:
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
216 pre_invalidate = repo_name in invalidation_list
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
217
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
218 if pre_invalidate:
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
219 invalidate = self._should_invalidate(repo_name)
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
220
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
221 if invalidate:
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
222 log.info('invalidating cache for repository %s', repo_name)
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
223 region_invalidate(_get_repo, None, repo_name)
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
224 self._mark_invalidated(invalidate)
4c16ed1eb699 fixed bug introduced in latest commit
Marcin Kuzminski <marcin@python-works.com>
parents: 791
diff changeset
225
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
226 return _get_repo(repo_name)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
227
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
228
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
229
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
230 def mark_for_invalidation(self, repo_name):
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
231 """
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
232 Puts cache invalidation task into db for
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
233 further global cache invalidation
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
234
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
235 :param repo_name: this repo that should invalidation take place
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
236 """
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
237 log.debug('marking %s for invalidation', repo_name)
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
238 cache = self.sa.query(CacheInvalidation)\
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
239 .filter(CacheInvalidation.cache_key == repo_name).scalar()
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
240
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
241 if cache:
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
242 #mark this cache as inactive
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
243 cache.cache_active = False
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
244 else:
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
245 log.debug('cache key not found in invalidation db -> creating one')
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
246 cache = CacheInvalidation(repo_name)
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
247
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
248 try:
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
249 self.sa.add(cache)
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
250 self.sa.commit()
758
6a31e64acabd code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 757
diff changeset
251 except (DatabaseError,):
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
252 log.error(traceback.format_exc())
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
253 self.sa.rollback()
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
254
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
255
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
256 def toggle_following_repo(self, follow_repo_id, user_id):
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
257
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
258 f = self.sa.query(UserFollowing)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
259 .filter(UserFollowing.follows_repo_id == follow_repo_id)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
260 .filter(UserFollowing.user_id == user_id).scalar()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
261
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
262 if f is not None:
747
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
263
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
264 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
265 self.sa.delete(f)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
266 self.sa.commit()
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
267 action_logger(UserTemp(user_id),
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
268 'stopped_following_repo',
747
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
269 RepoTemp(follow_repo_id))
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
270 return
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
271 except:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
272 log.error(traceback.format_exc())
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
273 self.sa.rollback()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
274 raise
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
275
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
276
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
277 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
278 f = UserFollowing()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
279 f.user_id = user_id
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
280 f.follows_repo_id = follow_repo_id
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
281 self.sa.add(f)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
282 self.sa.commit()
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
283 action_logger(UserTemp(user_id),
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
284 'started_following_repo',
747
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
285 RepoTemp(follow_repo_id))
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
286 except:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
287 log.error(traceback.format_exc())
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
288 self.sa.rollback()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
289 raise
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
290
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
291 def toggle_following_user(self, follow_user_id , user_id):
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
292 f = self.sa.query(UserFollowing)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
293 .filter(UserFollowing.follows_user_id == follow_user_id)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
294 .filter(UserFollowing.user_id == user_id).scalar()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
295
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
296 if f is not None:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
297 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
298 self.sa.delete(f)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
299 self.sa.commit()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
300 return
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
301 except:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
302 log.error(traceback.format_exc())
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
303 self.sa.rollback()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
304 raise
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
305
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
306 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
307 f = UserFollowing()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
308 f.user_id = user_id
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
309 f.follows_user_id = follow_user_id
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
310 self.sa.add(f)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
311 self.sa.commit()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
312 except:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
313 log.error(traceback.format_exc())
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
314 self.sa.rollback()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
315 raise
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
316
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
317 def is_following_repo(self, repo_name, user_id):
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
318 r = self.sa.query(Repository)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
319 .filter(Repository.repo_name == repo_name).scalar()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
320
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
321 f = self.sa.query(UserFollowing)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
322 .filter(UserFollowing.follows_repository == r)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
323 .filter(UserFollowing.user_id == user_id).scalar()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
324
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
325 return f is not None
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
326
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
327 def is_following_user(self, username, user_id):
758
6a31e64acabd code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 757
diff changeset
328 u = UserModel(self.sa).get_by_username(username)
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
329
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
330 f = self.sa.query(UserFollowing)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
331 .filter(UserFollowing.follows_user == u)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
332 .filter(UserFollowing.user_id == user_id).scalar()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
333
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
334 return f is not None
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
335
747
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
336 def get_followers(self, repo_id):
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
337 return self.sa.query(UserFollowing)\
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
338 .filter(UserFollowing.follows_repo_id == repo_id).count()
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
339
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
340 def get_forks(self, repo_id):
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
341 return self.sa.query(Repository)\
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
342 .filter(Repository.fork_id == repo_id).count()
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
343
784
30d3161c6683 Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 767
diff changeset
344
30d3161c6683 Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 767
diff changeset
345 def get_unread_journal(self):
30d3161c6683 Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 767
diff changeset
346 return self.sa.query(UserLog).count()
30d3161c6683 Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 767
diff changeset
347
30d3161c6683 Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 767
diff changeset
348
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
349 def _should_invalidate(self, repo_name):
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
350 """
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
351 Looks up database for invalidation signals for this repo_name
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
352 :param repo_name:
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
353 """
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
354
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
355 ret = self.sa.query(CacheInvalidation)\
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
356 .options(FromCache('sql_cache_short',
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
357 'get_invalidation_%s' % repo_name))\
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
358 .filter(CacheInvalidation.cache_key == repo_name)\
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
359 .filter(CacheInvalidation.cache_active == False)\
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
360 .scalar()
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
361
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
362 return ret
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
363
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
364 def _mark_invalidated(self, cache_key):
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
365 """
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
366 Marks all occurences of cache to invaldation as already invalidated
758
6a31e64acabd code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 757
diff changeset
367 :param repo_name:
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
368 """
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
369 if cache_key:
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
370 log.debug('marking %s as already invalidated', cache_key)
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
371 try:
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
372 cache_key.cache_active = True
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
373 self.sa.add(cache_key)
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
374 self.sa.commit()
758
6a31e64acabd code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 757
diff changeset
375 except (DatabaseError,):
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
376 log.error(traceback.format_exc())
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
377 self.sa.rollback()
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
378