Ticket #6436: cache-get_ticket_fields-r6823.diff
| File cache-get_ticket_fields-r6823.diff, 1.7 kB (added by cboos, 5 months ago) |
|---|
-
trac/ticket/api.py
16 16 17 17 import re 18 18 from datetime import datetime 19 try: 20 import threading 21 except ImportError: 22 import dummy_threading as threading 19 23 20 24 from genshi.builder import tag 21 25 … … 152 156 def __init__(self): 153 157 self.log.debug('action controllers for ticket workflow: %r' % 154 158 [c.__class__.__name__ for c in self.action_controllers]) 159 self._fields_lock = threading.RLock() 155 160 156 161 # Public API 157 162 … … 180 185 181 186 def get_ticket_fields(self): 182 187 """Returns the list of fields available for tickets.""" 188 # This is now cached - as it makes quite a number of things faster, 189 # e.g. #6436 190 if self._fields is None: 191 self._fields_lock.acquire() 192 try: 193 self._fields = self._get_ticket_fields() 194 finally: 195 self._fields_lock.release() 196 return self._fields 197 198 _fields = None 199 def _get_ticket_fields(self): 183 200 from trac.ticket import model 184 201 185 202 db = self.env.get_db_cnx() … … 251 268 return fields 252 269 253 270 def get_custom_fields(self): 271 if self._custom_fields is None: 272 self._fields_lock.acquire() 273 try: 274 self._custom_fields = self._get_custom_fields() 275 finally: 276 self._fields_lock.release() 277 return self._custom_fields 278 279 _custom_fields = None 280 def _get_custom_fields(self): 254 281 fields = [] 255 282 config = self.config['ticket-custom'] 256 283 for name in [option for option, value in config.options()
