As designed \XF\Entity\User::cacheNodePermissions() does not update loaded permission set

Lukas W.

Well-known member
Affected version
2.2.0
As per title, running cacheNodePermissions() does not affect the already loaded PermissionSet on the user object, hence voiding the usefulness of this method. Instead need to call $user->PermissionSet->cacheAllContentPerms('node');, which doesn't allow to pre-cache only a subset.
 
I won't close this yet, but this is very much as designed. It's designed to be a way to bulk load permission sets that you're going to need, if you don't have them. Repeated calls should use the cached values if they're available.

The "cache all" approach is really the exception to the rule in this class, and it's mostly because we don't know what sets we don't have without them being enumerated -- this method could certainly be updated to not overwrite the local cache if a value was already there.

Generally speaking, there's no real expectation of a user's permissions being changed and that necessarily instantly being reflected within the current request. There are situations where significant rebuilds have to happen so it can take a bit of time for changes to apply.

So what is the use case that causes issues? If anything, it sounds more like you may need a system to explicitly remove cached sets, though that might have other knock on effects I'm not anticipating.
 
Looks like I've just done a dumb here mostly. I was iterating over node ids and didn't know whether they existed or not, so my cache misses from invalid node ids produced extra queries. Not realizing that I tried to load the entire node permission set and reset the cache, but the function on the user object actually doesn't do the latter. Fixing my actual issue made the problem obsolete for me, but it seems a bit strange to me that the function on the user entity doesn't actually affect the same entities permission set.
 
Top Bottom