track account id and project id in the cache entry

This commit is contained in:
Conrad Ludgate
2025-07-26 10:24:05 +01:00
parent 3d2af1a83f
commit 8b299bfb4e

View File

@@ -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<RoleAccessControl>>,
ep_controls: Cache<EndpointIdInt, ControlPlaneResult<EndpointAccessControl>>,
role_controls:
Cache<(EndpointIdInt, RoleNameInt), ControlPlaneResult<Entry<RoleAccessControl>>>,
ep_controls: Cache<EndpointIdInt, ControlPlaneResult<Entry<EndpointAccessControl>>>,
project2ep: MultiSet<ProjectIdInt, EndpointIdInt>,
account2ep: MultiSet<AccountIdInt, EndpointIdInt>,
@@ -58,6 +59,13 @@ impl<'a, K: Ord, V> Comparable<Key<'a, K>> for KeyValue<K, V> {
}
}
#[derive(Clone)]
struct Entry<T> {
project_id: Option<ProjectIdInt>,
account_id: Option<AccountIdInt>,
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(