@@ -43,7 +43,7 @@ def results
4343 def load_gdt_results
4444 query = QueryBuilder . new ( @enhanced_query ) . query
4545
46- response = cache_timdex_query ( query )
46+ response = query_timdex ( query )
4747
4848 # Handle errors
4949 @errors = extract_errors ( response )
@@ -53,7 +53,7 @@ def load_gdt_results
5353 end
5454
5555 def load_primo_results
56- primo_response = cache_primo_query
56+ primo_response = query_primo
5757 @results = NormalizePrimoResults . new ( primo_response , @enhanced_query [ :q ] ) . normalize
5858
5959 # Enhanced pagination using cached response
@@ -74,7 +74,7 @@ def load_primo_results
7474
7575 def load_timdex_results
7676 query = QueryBuilder . new ( @enhanced_query ) . query
77- response = cache_timdex_query ( query )
77+ response = query_timdex ( query )
7878
7979 @errors = extract_errors ( response )
8080 @pagination = Analyzer . new ( @enhanced_query , response ) . pagination if @errors . nil?
@@ -85,25 +85,29 @@ def active_filters
8585 ENV . fetch ( 'ACTIVE_FILTERS' , '' ) . split ( ',' ) . map ( &:strip )
8686 end
8787
88- def cache_timdex_query ( query )
88+ def query_timdex ( query )
89+ # We generate unique cache keys to avoid naming collisions.
8990 cache_key = generate_cache_key ( query )
9091
91- # builder hands off to wrapper which returns raw results here
92- # The response type is a GraphQL::Client::Response, which is not directly serializable, so we convert it to a hash.
92+ # Builder hands off to wrapper which returns raw results here.
9393 Rails . cache . fetch ( "#{ cache_key } /#{ @active_tab } " , expires_in : 12 . hours ) do
9494 raw = if @active_tab == 'gdt'
9595 execute_geospatial_query ( query )
9696 elsif @active_tab == 'timdex'
9797 TimdexBase ::Client . query ( TimdexSearch ::BaseQuery , variables : query )
9898 end
99+
100+ # The response type is a GraphQL::Client::Response, which is not directly serializable, so we
101+ # convert it to a hash.
99102 {
100103 data : raw . data . to_h ,
101104 errors : raw . errors . details . to_h
102105 }
103106 end
104107 end
105108
106- def cache_primo_query
109+ def query_primo
110+ # We generate unique cache keys to avoid naming collisions.
107111 cache_key = generate_cache_key ( @enhanced_query )
108112
109113 Rails . cache . fetch ( "#{ cache_key } /primo" , expires_in : 12 . hours ) do
@@ -113,10 +117,6 @@ def cache_primo_query
113117 end
114118 end
115119
116- # We are using two difference caches to allow for Geo and USE to be cached separately. This ensures we don't have
117- # cache key collision for these two different query types. In practice, the likelihood of this happening is low,
118- # as the query parameters are different for each type and they won't often be run with the same cache backend other
119- # than locally, but this is a safeguard.
120120 def generate_cache_key ( query )
121121 # Sorting query hash to ensure consistent key generation regardless of the parameter order
122122 sorted_query = query . sort_by { |k , _v | k . to_sym } . to_h
0 commit comments