More on this, another quite impressive case.
In order to manage user-access to functions, I use a âbitwiseâ approach:
- each authorizable functionality has an integer ID corresponding to a specific bit position (es. 1 / 2 / 4 / 8 / 16 / 32 / âŚ)
- each combination of authorized functionalities is represented by an INT given by the sum of the single IDs (es 4+8=12 means user is authorized to the third and fourth functionalities)
- each user has a permissions field with the INT of their authorized functionalities.
Being that, when I have to check if - for instance - the button btn_starpvda has to be shown to the user, I call
self.btn_starpvda.visible = anvil.server.call('can_use',user['permissions'],'btn_starpvda')
The function can_use is very simple, it queries the permissions table:
@anvil.server.callable
def can_use(user_permissions, functionality):
permission_id = app_tables.permissions.get(perm_functionality = functionality)
# Bitwise check
return ((permission_id['perm_id'] & user_permissions) == permission_id['perm_id'])
The permissions table has 12 (!!) records.
When I check (in the client code) for several buttons to show, this is the code:
print "Button enabling"
print datetime.datetime.now()
self.btn_starpvda.visible = anvil.server.call('can_use',user['permissions'],'btn_starpvda')
print datetime.datetime.now()
self.btn_scarica_dati.visible = anvil.server.call('can_use',user['permissions'],'btn_scarica_dati')
print datetime.datetime.now()
self.btn_recalc_stats.visible = anvil.server.call('can_use',user['permissions'],'btn_recalc_games')
print datetime.datetime.now()
self.btn_insulti.visible = anvil.server.call('can_use',user['permissions'],'btn_insulti')
print datetime.datetime.now()
And this is the timeline:
Button enabling
2019-09-28 15:34:17.045100
2019-09-28 15:34:17.337570
2019-09-28 15:34:17.992960
2019-09-28 15:34:18.680005
2019-09-28 15:34:19.338165
It looks really slow to me, even though, being on the free plan, I understand I have no indexes.
But itâs a 12 records table.
Thanks.