diff --git a/proxy/src/cache/project_info.rs b/proxy/src/cache/project_info.rs index b8aa445e5c..2c834ca306 100644 --- a/proxy/src/cache/project_info.rs +++ b/proxy/src/cache/project_info.rs @@ -23,8 +23,9 @@ use crate::types::{EndpointId, RoleName}; /// One may ask, why the data is stored per project, when on the user request there is only data about the endpoint available? /// On the cplane side updates are done per project (or per branch), so it's easier to invalidate the whole project cache. pub struct ProjectInfoCache { - role_controls: Cache<(EndpointIdInt, RoleNameInt), ControlPlaneResult>, - ep_controls: Cache>, + role_controls: + Cache<(EndpointIdInt, RoleNameInt), ControlPlaneResult>>, + ep_controls: Cache>>, project2ep: MultiSet, account2ep: MultiSet, @@ -58,6 +59,13 @@ impl<'a, K: Ord, V> Comparable> for KeyValue { } } +#[derive(Clone)] +struct Entry { + project_id: Option, + account_id: Option, + value: T, +} + impl ProjectInfoCache { pub fn invalidate_endpoint_access(&self, endpoint_id: EndpointIdInt) { info!("invalidating endpoint access for `{endpoint_id}`"); @@ -144,7 +152,9 @@ impl ProjectInfoCache { count_cache_outcome( CacheKind::ProjectInfoRoles, - self.role_controls.get(&(endpoint_id, role_name)), + self.role_controls + .get(&(endpoint_id, role_name)) + .map(|e| e.map(|e| e.value)), ) } @@ -156,7 +166,9 @@ impl ProjectInfoCache { count_cache_outcome( CacheKind::ProjectInfoEndpoints, - self.ep_controls.get(&endpoint_id), + self.ep_controls + .get(&endpoint_id) + .map(|e| e.map(|e| e.value)), ) } @@ -184,9 +196,22 @@ impl ProjectInfoCache { count_cache_insert(CacheKind::ProjectInfoEndpoints); count_cache_insert(CacheKind::ProjectInfoRoles); - self.ep_controls.insert(endpoint_id, Ok(controls)); - self.role_controls - .insert((endpoint_id, role_name), Ok(role_controls)); + self.ep_controls.insert( + endpoint_id, + Ok(Entry { + account_id, + project_id, + value: controls, + }), + ); + self.role_controls.insert( + (endpoint_id, role_name), + Ok(Entry { + account_id, + project_id, + value: role_controls, + }), + ); } pub(crate) fn insert_endpoint_access_err(