##// END OF EJS Templates
Don't create one big transaction when doing cache-keys cleanup....
marcink -
r3977:7c84b383 default
parent child Browse files
Show More
@@ -1,84 +1,84 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.lib.paster_commands.cache_keys
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 cleanup-keys paster command for RhodeCode
7 7
8 8
9 9 :created_on: mar 27, 2013
10 10 :author: marcink
11 11 :copyright: (C) 2010-2013 Marcin Kuzminski <marcin@python-works.com>
12 12 :license: GPLv3, see COPYING for more details.
13 13 """
14 14 # This program is free software: you can redistribute it and/or modify
15 15 # it under the terms of the GNU General Public License as published by
16 16 # the Free Software Foundation, either version 3 of the License, or
17 17 # (at your option) any later version.
18 18 #
19 19 # This program is distributed in the hope that it will be useful,
20 20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 22 # GNU General Public License for more details.
23 23 #
24 24 # You should have received a copy of the GNU General Public License
25 25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 26 from __future__ import with_statement
27 27
28 28 import os
29 29 import sys
30 30 import logging
31 31
32 32 from rhodecode.model.meta import Session
33 33 from rhodecode.lib.utils import BasePasterCommand
34 34 from rhodecode.model.db import CacheInvalidation
35 35
36 36 # fix rhodecode import
37 37 from os.path import dirname as dn
38 38 rc_path = dn(dn(dn(os.path.realpath(__file__))))
39 39 sys.path.append(rc_path)
40 40
41 41 log = logging.getLogger(__name__)
42 42
43 43
44 44 class Command(BasePasterCommand):
45 45
46 46 max_args = 1
47 47 min_args = 1
48 48
49 49 usage = "CONFIG_FILE"
50 50 group_name = "RhodeCode"
51 51 takes_config_file = -1
52 52 parser = BasePasterCommand.standard_parser(verbose=True)
53 53 summary = "Cache keys utils"
54 54
55 55 def command(self):
56 56 #get SqlAlchemy session
57 57 self._init_session()
58 58 _caches = CacheInvalidation.query().order_by(CacheInvalidation.cache_key).all()
59 59 if self.options.show:
60 60 for c_obj in _caches:
61 61 print 'key:%s active:%s' % (c_obj.cache_key, c_obj.cache_active)
62 62 elif self.options.cleanup:
63 63 for c_obj in _caches:
64 64 Session().delete(c_obj)
65 65 print 'removing key:%s' % (c_obj.cache_key)
66 Session().commit()
66 Session().commit()
67 67 else:
68 68 print 'nothing done exiting...'
69 69 sys.exit(0)
70 70
71 71 def update_parser(self):
72 72 self.parser.add_option(
73 73 '--show',
74 74 action='store_true',
75 75 dest='show',
76 76 help=("show existing cache keys with together with status")
77 77 )
78 78
79 79 self.parser.add_option(
80 80 '--cleanup',
81 81 action="store_true",
82 82 dest="cleanup",
83 83 help="cleanup existing cache keys"
84 84 )
General Comments 0
You need to be logged in to leave comments. Login now