mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-06 09:30:49 +00:00
perf: naive permission cache
Add a simple 20 second cache with kv.js to the scan_ method of PermissionService. This will not improve the performance for the permission system, but it will invoke it less often.
This commit is contained in:
@@ -265,6 +265,10 @@ class PermissionUtil {
|
||||
* This service interacts with the database to manage permissions and logs actions for auditing purposes.
|
||||
*/
|
||||
class PermissionService extends BaseService {
|
||||
static MODULES = {
|
||||
kv: globalThis.kv,
|
||||
}
|
||||
|
||||
static CONCERN = 'permissions';
|
||||
/**
|
||||
* Initializes the PermissionService by setting up internal arrays for permission handling.
|
||||
@@ -369,6 +373,18 @@ class PermissionService extends BaseService {
|
||||
if ( ! Array.isArray(permission_options) ) {
|
||||
permission_options = [permission_options];
|
||||
}
|
||||
|
||||
const cache_str = PermissionUtil.join(
|
||||
'permission-scan',
|
||||
actor.uid,
|
||||
'options-list',
|
||||
...permission_options,
|
||||
);
|
||||
|
||||
const cached = kv.get(cache_str);
|
||||
if ( cached ) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
// TODO: command to enable these logs
|
||||
// const l = get_a_letter();
|
||||
@@ -392,6 +408,8 @@ class PermissionService extends BaseService {
|
||||
value: end_ts - start_ts,
|
||||
});
|
||||
|
||||
kv.set(cache_str, reading, { EX: 20 });
|
||||
|
||||
return reading;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user