Trac is being migrated to new services! Issues can be found in our new
YouTrack instance and WIKI pages can be found on our
website.
LocalTracChanges: cached_restrict_users_list.diff
File cached_restrict_users_list.diff, 2.9 KB (added by datallah, 16 years ago) |
Patch to cache list of users to whom a ticket can be assigned
|
-
old
|
new
|
|
24 | 24 | from trac.util.text import shorten_line |
25 | 25 | from trac.wiki import IWikiSyntaxProvider, Formatter |
26 | 26 | |
| 27 | try: |
| 28 | import threading |
| 29 | except ImportError: |
| 30 | import dummy_threading as threading |
27 | 31 | |
28 | 32 | class ITicketChangeListener(Interface): |
29 | 33 | """Extension point interface for components that require notification when |
… |
… |
|
68 | 72 | [TracTickets#Assign-toasDrop-DownList Assign-to as Drop-Down List] |
69 | 73 | (''since 0.9'').""") |
70 | 74 | |
| 75 | cached_users = None |
| 76 | cached_perm_id = None |
| 77 | _cache_lock = threading.Lock() |
| 78 | |
71 | 79 | # Public API |
72 | 80 | |
73 | 81 | def get_available_actions(self, ticket, perm_): |
… |
… |
|
99 | 107 | field = {'name': 'owner', 'label': 'Owner'} |
100 | 108 | if self.restrict_owner: |
101 | 109 | field['type'] = 'select' |
102 | | users = [] |
103 | | perm = PermissionSystem(self.env) |
104 | | for username, name, email in self.env.get_known_users(db): |
105 | | if perm.get_user_permissions(username).get('TICKET_MODIFY'): |
106 | | users.append(username) |
107 | | field['options'] = users |
108 | | field['optional'] = True |
| 110 | |
| 111 | perm_id = None |
| 112 | try: |
| 113 | db = self.env.get_db_cnx() |
| 114 | cursor = db.cursor() |
| 115 | cursor.execute("SELECT value FROM system WHERE name = 'perm_id'") |
| 116 | perm_row = cursor.fetchone() |
| 117 | cursor.close() |
| 118 | if not perm_row: |
| 119 | raise TracError('perm_id KVP in system table missing', |
| 120 | 'Invalid restricted owner caching data - is the trigger running?') |
| 121 | perm_id = perm_row[0]; |
| 122 | except: |
| 123 | pass |
| 124 | |
| 125 | """We check once before locking and once after to prevent locking when we don't need to """ |
| 126 | if self.cached_users is None or (perm_id is not None and perm_id > self.cached_perm_id): |
| 127 | |
| 128 | self._cache_lock.acquire() |
| 129 | try: |
| 130 | if self.cached_users is None or (perm_id is not None and perm_id > self.cached_perm_id): |
| 131 | users = [] |
| 132 | perm = PermissionSystem(self.env) |
| 133 | for username, name, email in self.env.get_known_users(db): |
| 134 | if perm.get_user_permissions(username).get('TICKET_MODIFY'): |
| 135 | users.append(username) |
| 136 | self.cached_users = users; |
| 137 | if perm_id is not None: |
| 138 | self.cached_perm_id = perm_id |
| 139 | finally: |
| 140 | self._cache_lock.release() |
| 141 | |
| 142 | if self.cached_users is not None: |
| 143 | field['options'] = self.cached_users |
| 144 | field['optional'] = True |
| 145 | else: |
| 146 | field['type'] = 'text' |
109 | 147 | else: |
110 | 148 | field['type'] = 'text' |
111 | 149 | fields.append(field) |
Download in other formats:
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!