Keep network calls out of post transactions; cache and throttle geocoding

- PostService.create/update geocode and upload photos before opening the DB
  transaction (TransactionTemplate); uploaded files are removed if the
  transaction fails, so a DB connection is no longer held while waiting for
  Nominatim or MinIO.
- GeocodingService: configurable URL and User-Agent (geocoding.*), results
  cached in Redis for 30 days by coordinates rounded to ~11 m, and a
  cluster-wide 1 request/s slot (geo:throttle) as the public Nominatim policy
  requires; city/district are cut to the column sizes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SlimusMinus
2026-10-20 01:41:03 +03:00
parent 85a2773f60
commit 3dcd27d08a
4 changed files with 265 additions and 59 deletions

View File

@@ -73,6 +73,13 @@ ai:
delay: 500
multiplier: 2
# Обратное геокодирование (GeocodingService): публичный Nominatim требует
# User-Agent с контактом и не больше 1 запроса/с; для нагрузки — свой экземпляр
geocoding:
url: ${GEOCODING_URL:https://nominatim.openstreetmap.org}
user-agent: ${GEOCODING_USER_AGENT:ReFound-backend/1.0}
min-interval: ${GEOCODING_MIN_INTERVAL:PT1S}
# Поиск по объявлениям (PostSearchService)
search:
typo-threshold: 0.3