Refactor ClickHouse queries of ee/app/services/analytics/ai_analytics/ classes
Some service classes, especially the ones that are inheriting from CommonUsageService, have ClickHouse queries defined as strings in constants. This eventually becomes harder to maintain and forces workarounds when adding conditions to the queries, for example, in !196477 (merged) we had to introduce a regex replace to be able to use a filter in the query behind the feature flag.
We should refactor all classes from ee/app/services/analytics/ai_analytics/ folder to use ClickHouse::QueryBuilder instead of raw queries to dry up the code and make it more maintainable.
The following discussion from !196477 (merged) should be addressed:
-
@pshutsin started a discussion: (+5 comments)
ah I see now why.
I guess it's ok for now but I'm pretty sure we need to switch to AR based query building pretty soon. Strings approach is not maintainable.