Edgewall Software

Ticket #6436: cache-get_ticket_fields-r6823.diff

File cache-get_ticket_fields-r6823.diff, 1.7 kB (added by cboos, 5 months ago)

Same as first patch but with locking add (for latest 0.11dev trunk)

  • trac/ticket/api.py

     
    1616 
    1717import re 
    1818from datetime import datetime 
     19try: 
     20    import threading 
     21except ImportError: 
     22    import dummy_threading as threading 
    1923 
    2024from genshi.builder import tag 
    2125 
     
    152156    def __init__(self): 
    153157        self.log.debug('action controllers for ticket workflow: %r' %  
    154158                [c.__class__.__name__ for c in self.action_controllers]) 
     159        self._fields_lock = threading.RLock() 
    155160 
    156161    # Public API 
    157162 
     
    180185 
    181186    def get_ticket_fields(self): 
    182187        """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): 
    183200        from trac.ticket import model 
    184201 
    185202        db = self.env.get_db_cnx() 
     
    251268        return fields 
    252269 
    253270    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): 
    254281        fields = [] 
    255282        config = self.config['ticket-custom'] 
    256283        for name in [option for option, value in config.options()