Closed (fixed)
Project:
Search API
Version:
8.x-1.x-dev
Component:
Views integration
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
3 Nov 2024 at 15:51 UTC
Updated:
23 Dec 2024 at 14:54 UTC
Jump to comment: Most recent
Comments
Comment #2
mably commentedComment #3
mably commentedHere is the code that sets the cache:
https://git.drupalcode.org/project/search_api/-/blob/8.x-1.35/src/Plugin/views/cache/SearchApiCachePluginTrait.php?ref_type=tags#L118-125
Comment #4
mably commentedSetting the
search_api_viewquery option toNULLlogically disables the serialization of the ViewExecutable object.Small hack of the
cacheSetmethod:And then we could add it back in the
cacheGetmethod:Comment #5
mably commentedComment #8
drunken monkeyThanks a lot for reporting this problem and already providing an MR!
You’re right, caching the view object here makes no sense at all and can lead to various unintended consequences. We also already remove that option when storing the query as part of a saved search in the Saved Searches module (see here) for the same reason. So removing it here seems like a very good idea.
Looking at the cache contents for SQL views and at
\Drupal\views\Plugin\views\cache\CachePluginBase::cacheSet(), though, it seems like they even avoid caching the result entities, which might not be as much a potential source of bugs but might bloat the cache size considerably. So doing something similar in our cache plugins might be a good next step – probably in a follow-up issue, though.Regarding the concrete code in your MR I spotted a potential problem when the
$expire === 0line is true, since thesearch_api_viewoption values would then not be restored. I now just moved all that code down to right before the$this->getCacheBackend()->set()call and threw in atry/finallyfor good measure to make extra-sure this temporary change will always be reverted. (It would also have worked without moving the$datainitialization down, too, but I found it clearer this way and there doesn’t actually seem to be a reason it was initialized so far up in the method body until now.)One final question: I see that in
cacheGet()you don’t set thesearch_api_viewoption on the original query. I assume that’s because that is alwaysnullat this point, or what’s the reason? (In hindsight, it seems an oversight that there is no way to tell whether the$originalQueryproperty is actually set on a query, but I guess this issue is the wrong place to add it.)Otherwise, please just test/review the modified MR and I can merge it.
In any case, thanks again, and sorry for the delay.
Comment #9
mably commentedHi @drunken-monkey, tested locally, seems to work perfectly fine.
At least, I don't the problems I had before with Views Bulk Operations, no more double instantiations.
Thanks for the improvements and fixes!
Comment #10
mably commentedComment #11
drunken monkeyGreat to hear, thanks a lot for testing!
Merged.
Thanks again!
Comment #12
mably commentedYou're welcome 🙂