Cache Elasticsearch enabled check in Redis
Related to https://gitlab.com/gitlab-com/gl-infra/infrastructure/-/issues/9447#note_302066872 we are querying to see if a project is enabled in Elasticsearch very frequently (on every write to many tables). Since this fires off a DB query and since the answer changes very infrequently it may be worth caching the answer (presumably in Redis). It's also possibly even more beneficial because today this query is always sent to master node after a write so this puts high load on the master DB.
We could cache in Redis and only bust cache when there is a change to ElasticsearchIndexedNamespace
or ElasticsearchIndexedProject
.
Since we need to cache the answer to "is this project enabled for Elasticsearch" for every single project this may be an expensive cache in terms of memory. Of course using TTL can certainly help for inactive projects but we will want to consider this cost when implementing. I guess a couple million boolean key/value pairs in Redis isn't likely to break the bank but we'll want to optimize key size for sure and get an understanding of the rough total size.