Implement Category Predecessor Cache
|Assignee:||Pavan Rikhi||% Done:|
|Target version:||v0.7.0 - Misc Pages & UI|
Currently, when we need to fetch the predecessors for a category, we do a single query for each level of category nesting.
This gets intensive for some pages, e.g. any page that checks for category sales & the products/category details pages.
Instead, we should keep a
Map CategoryId [CategoryId] in the application config that maps a category to a list of it's predecessors. Then we can simply pull the value out of there instead of running a ridiculous amount of many queries.
Make sure to update the map when changes are made to the categories via the Category Admin.
[#1544] Add Caching for Category Predecessors
Add a Cache module containing types & functions for building a cached
Map from CategoryIds to a list of that Category's predecessor
This cache is initialized when the server starts & is stored in a
thread-safe TVar. Resyncing is not necessary at this point, but will be
required when the Category admin page is implemented and the category
hierarchy can change.
Modify the getParentCategories function in the Models.Utils module to
use the CategoryPredecessorCache to get the parent categories instead of
recursive SQL queries.
Add helper functions to the Server module for reading & writing to the