From 689b8cb0f1a5a5f6c1044b591163559379b6b76c Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Wed, 3 Sep 2025 19:56:38 +0200 Subject: [PATCH] Remove caching from geocoder --- .../location_search/geocoding_service.rb | 8 +---- app/services/location_search/point_finder.rb | 36 ++----------------- .../location_search/geocoding_service_spec.rb | 21 ----------- 3 files changed, 4 insertions(+), 61 deletions(-) diff --git a/app/services/location_search/geocoding_service.rb b/app/services/location_search/geocoding_service.rb index 9bf29c2b..d81a4da1 100644 --- a/app/services/location_search/geocoding_service.rb +++ b/app/services/location_search/geocoding_service.rb @@ -3,21 +3,15 @@ module LocationSearch class GeocodingService MAX_RESULTS = 10 - CACHE_TTL = 1.hour def initialize(query) @query = query - @cache_key_prefix = 'location_search:geocoding' end def search return [] if query.blank? - cache_key = "#{@cache_key_prefix}:#{Digest::SHA256.hexdigest(query.downcase)}" - - Rails.cache.fetch(cache_key, expires_in: CACHE_TTL) do - perform_geocoding_search(query) - end + perform_geocoding_search(query) rescue StandardError => e Rails.logger.error "Geocoding search failed for query '#{query}': #{e.message}" [] diff --git a/app/services/location_search/point_finder.rb b/app/services/location_search/point_finder.rb index d46e07ae..7b9a2d01 100644 --- a/app/services/location_search/point_finder.rb +++ b/app/services/location_search/point_finder.rb @@ -13,20 +13,6 @@ module LocationSearch end def call - if coordinate_search? - return coordinate_based_search - else - return empty_result - end - end - - private - - def coordinate_search? - @latitude.present? && @longitude.present? - end - - def coordinate_based_search location = { lat: @latitude, lon: @longitude, @@ -36,13 +22,12 @@ module LocationSearch find_matching_points([location]) end + private + def find_matching_points(geocoded_locations) results = [] geocoded_locations.each do |location| - # Debug: Log the geocoded location - Rails.logger.info "LocationSearch: Searching for points near #{location[:name]} at [#{location[:lat]}, #{location[:lon]}]" - search_radius = @radius_override || determine_search_radius(location[:type]) matching_points = spatial_matcher.find_points_near( @@ -53,11 +38,7 @@ module LocationSearch date_filter_options ) - # Debug: Log the number of matching points found - Rails.logger.info "LocationSearch: Found #{matching_points.length} points within #{search_radius}m radius" - if matching_points.empty? - # Try with a larger radius to see if there are any points nearby wider_search = spatial_matcher.find_points_near( @user, location[:lat], @@ -65,7 +46,7 @@ module LocationSearch 1000, # 1km radius for debugging date_filter_options ) - Rails.logger.info "LocationSearch: Found #{wider_search.length} points within 1000m radius (debug)" + next end @@ -122,16 +103,5 @@ module LocationSearch 500 # Default radius for unknown types end end - - def empty_result - { - locations: [], - total_locations: 0, - search_metadata: { - candidates_found: 0, - search_time_ms: 0 - } - } - end end end diff --git a/spec/services/location_search/geocoding_service_spec.rb b/spec/services/location_search/geocoding_service_spec.rb index 70c95f25..ddbfa699 100644 --- a/spec/services/location_search/geocoding_service_spec.rb +++ b/spec/services/location_search/geocoding_service_spec.rb @@ -51,32 +51,11 @@ RSpec.describe LocationSearch::GeocodingService do ) end - it 'caches results' do - expect(Rails.cache).to receive(:fetch).and_call_original - - service.search - end - it 'limits results to MAX_RESULTS' do expect(Geocoder).to receive(:search).with(query, limit: 10) service.search end - - context 'with cached results' do - let(:cached_results) { [{ lat: 1.0, lon: 2.0, name: 'Cached' }] } - - before do - allow(Rails.cache).to receive(:fetch).and_return(cached_results) - end - - it 'returns cached results without calling Geocoder' do - expect(Geocoder).not_to receive(:search) - - results = service.search - expect(results).to eq(cached_results) - end - end end context 'with blank query' do