view tools/fixroles.py @ 6747:d32d43e4a5ba

wsgi can cache tracker instance enabled by feature flag. Patch by Marcus Priesch caches a loaded tracker instance and reuse it for future client sessions. It is enabled by a feature flag in wsgi.py since it arrived during the 2.2.0 beta period. The provided wsgi.py is modified to enable it. Testing is run with flag enabled and disabled. Ralf Schlatterbeck and Marcus tested it on one of their larger more complex trackers and it sped up the response time to a client request by a factor of 3 (270ms down to about 80-85ms).
author John Rouillard <rouilj@ieee.org>
date Sat, 02 Jul 2022 14:04:00 -0400
parents 52c8324d1539
children
line wrap: on
line source

import sys

from roundup import admin

class AdminTool(admin.AdminTool):
    def __init__(self):
        self.commands = admin.CommandDict()
        for k in AdminTool.__dict__.keys():
            if k[:3] == 'do_':
                self.commands[k[3:]] = getattr(self, k)
        self.help = {}
        for k in AdminTool.__dict__.keys():
            if k[:5] == 'help_':
                self.help[k[5:]] = getattr(self, k)
        self.instance_home = ''
        self.db = None

    def do_fixroles(self, args):
        '''Usage: fixroles
        Set the roles property for all users to reasonable defaults.

        The admin user gets "Admin", the anonymous user gets "Anonymous"
        and all other users get "User".
        '''
        # get the user class
        cl = self.get_class('user')
        for userid in cl.list():
            username = cl.get(userid, 'username')
            if username == 'admin':
                roles = 'Admin'
            elif username == 'anonymous':
                roles = 'Anonymous'
            else:
                roles = 'User'
            cl.set(userid, roles=roles)
        return 0

if __name__ == '__main__':
    tool = AdminTool()
    sys.exit(tool.main())

Roundup Issue Tracker: http://roundup-tracker.org/