In T378983: Add Link recommendation are not being processed by CirrusSearch (November 2024), the Growth team is facing an issue with generating weighted tag updates. Unfortunately, the EventBusWeightedTagsUpdater implementation does not indicate its success status in any way. This information would be very useful, because Growth needs to do two things for each link recommendation generated:
- Update weighted tags in Search
- Add a row to its own database, which has details about the recommendation
Both the search index and the database need to be in sync (within certain bounds). If they are not, issues can happen relatively quickly. In other words, Growth's code needs to ensure that either both updates happen, or none of them.
The update method has the following signature:
public function updateWeightedTags( ProperPageIdentity $page, string $tagPrefix, ?array $tagWeights = null, ?string $trigger = null ): void;
which means the only way to indicate a failure is by throwing an exception. Growth's code handles any possible exception gracefully (and avoids updating its own database should WeightedTagsUpdater throw), but as far as I can see, WeightedTagsUpdater only logs an error if the update didn't go through (because of eg. validation errors), and the caller has no chance to know about that happening.
To avoid the out of sync issue, I propose to either:
- make WeightedTagsUpdater throw an exception if an update definitely did not go through,
- change the signature to allow informing the caller about the operation's result