PERF: Cache categories in Site model. (PR #13341)

GitHub

Shouldn’t we also clear the cache when we change the logo/background of a category?

The foreign keys for uploads are on the categories table itself so the callback on the category model will be triggered when the uploads change.

Mixed a bit on chucking a large amount of AR objects into the cache forcing all this marshalling.

Instead if we can do a more strategic cache when we keep a cache of the serialized format combined with category id, then you just keep the permission check based on id.

Caching all the AR stuff has potential to go wrong (adding a column to categories) giant object graph … etc.

@SamSaffron Good point. I don’t think we should ever be caching objects actually. I’ve updated the PR to be caching the json blob after serialization.

Note that I’m setting a TTL of 30 minutes here for a start in case something goes wrong. We can look at increasing this in the future. Better to err on the safe side.

this feels somewhat fragile.

instead I would define a special guardian that can_see_category calls.

maybe can_see_serialized_category(category_id, read_restricted) … not sure but the open struct there is not deliberate enough.

staged user check can be bypassed on the serialized form and maybe can_see_category calls it?

@SamSaffron I’ve simplified the check here as per what the original query was doing.

@SamSaffron Do this PR look ok to you?