Some companies listed as related to themselves
baltpeter opened this issue · 3 comments
We've received a report that some companies are listed as related to themselves, e.g. https://www.datarequests.org/company/ndr/:
This surprised me since we do already have a condition in place that should prevent this exact problem:
Debugging this, I found that $.Permalink
was wrong (for a different page).
That makes sense! We are heavily caching the related companies calculation (an optimization that is very necessary as explained in the commit message of bce6bff):
website/layouts/company/single.html
Line 119 in 005798d
However, we are only varying the cache based on the categories and relevant countries. Thus, we will get the wrong permalink for cached renders, of course.
Unfortunately, we can't just also pass the permalink to partialCached
. That would mean that nothing gets cached anymore.
Solution is a bit annoying but not too bad: We make the related companies partial into a function that returns an array of the candidates and then do the filtering on each individual page. Only question is how much of a performance impact that is, so let's do some benchmarking. Running on my machine (I ran each one multiple times to hopefully negate disk caching fluctuations):
- production
- before: 19219 ms, 19005 ms
- after: 19405 ms, 19181 ms
- dev
- before: 14565 ms, 14393 ms
- after: 14907 ms, 14685 ms
Looking good!