Skip to content

Cache ES indices in multi-version proxies

Summary

This is a follow-up to !17230 (closed) / !18254 (merged).

The methods elastic_reading_target and elastic_writing_targets in ee/lib/elastic/multi_version_util.rb store references to the current ElasticsearchIndex records from the database. These are currently un-memoized because on class-level proxies the values would persist across requests, and any changes made to the DB would not get picked up.

This is a bit problematic because these methods get called every time we're instantiating a new multi-version proxy to interact with ES (when searching or indexing). But the elasticsearch_indices table is only expected to contain a couple of records at most, so the performance impact should be fairly small.

Improvements

Implement some form of caching/expiration logic, possibly using Redis.

This is a very similar problem to the cached application settings and cached ES client instances mentioned in #36663 (comment 246231217). Maybe we could implement a general solution using Redis Pub/Sub.

Involved components

  • ee/lib/elastic/multi_version_util.rb
Edited by Markus Koller