Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not use expensive hash keys for cheap queries
Role.hashed uses Rails.all.cache_key - which is rather expensive SELECT COUNT(*) AS `size`, MAX(`roles`.`updated_at`) AS timestamp FROM `roles` to avoid querying 8 role titles. The problem is that all the other code expects Role.hashed to be cheaper than querying the database directly - which is no longer true with this approach. E.g. irb(main):001:0> Role.local_roles (0.2ms) SELECT COUNT(*) AS `size`, MAX(`roles`.`updated_at`) AS timestamp FROM `roles` (0.3ms) SELECT COUNT(*) AS `size`, MAX(`roles`.`updated_at`) AS timestamp FROM `roles` (0.2ms) SELECT COUNT(*) AS `size`, MAX(`roles`.`updated_at`) AS timestamp FROM `roles` (0.2ms) SELECT COUNT(*) AS `size`, MAX(`roles`.`updated_at`) AS timestamp FROM `roles` (0.2ms) SELECT COUNT(*) AS `size`, MAX(`roles`.`updated_at`) AS timestamp FROM `roles` I noticed these repeated queries when working on involved_packages and wondered since then what is going on.
- Loading branch information