feat(refactor): Document refactoring progress and phases in markdown
feat(scripts): Add backfill script for content_hash in cache tables feat(scripts): Create recompute script for analysis_cache population test(tests): Implement comprehensive tests for analysis module functions fix(tests): Update CLI tests to assert errors on stderr instead of stdout fix(tests): Adjust MCP integration tests to pass context parameter correctly fix(tests): Modify service tests to return hash on save functions for consistency
This commit is contained in:
+25
-4
@@ -30,9 +30,16 @@ from .cache import (
|
||||
invalidate_analysis,
|
||||
save_eiendom_unit,
|
||||
save_finn_ad,
|
||||
save_price_history,
|
||||
save_similar_units,
|
||||
)
|
||||
from .config import EIENDOM_NO_CACHE_TTL_HOURS, FINN_CACHE_PATH, FINN_CACHE_TTL_AD_HOURS
|
||||
from .config import (
|
||||
EIENDOM_NO_CACHE_TTL_ESTIMATE_DAYS,
|
||||
EIENDOM_NO_CACHE_TTL_SIMILAR_UNITS_DAYS,
|
||||
EIENDOM_NO_CACHE_TTL_STRUCTURAL_DAYS,
|
||||
FINN_CACHE_PATH,
|
||||
FINN_CACHE_TTL_AD_STRUCTURAL_DAYS,
|
||||
)
|
||||
from .eiendom_no import (
|
||||
build_unit_vector,
|
||||
decode_unit_vector,
|
||||
@@ -56,13 +63,23 @@ async def get_or_fetch_ad(finnkode: str, force_refresh: bool = False) -> FinnAd:
|
||||
invalidated.
|
||||
"""
|
||||
conn = init_db(FINN_CACHE_PATH)
|
||||
ad = None if force_refresh else get_finn_ad(conn, finnkode, ttl_hours=FINN_CACHE_TTL_AD_HOURS)
|
||||
# Convert structural TTL from days to hours
|
||||
ttl_hours = FINN_CACHE_TTL_AD_STRUCTURAL_DAYS * 24
|
||||
ad = None if force_refresh else get_finn_ad(conn, finnkode, ttl_hours=ttl_hours)
|
||||
if ad is not None:
|
||||
return ad
|
||||
|
||||
# Cache miss or force_refresh: fetch from remote.
|
||||
ad = await fetch_ad_details(finnkode)
|
||||
_, changed = save_finn_ad(conn, ad)
|
||||
# Record price snapshot for history tracking
|
||||
save_price_history(
|
||||
conn,
|
||||
finnkode,
|
||||
total_price=ad.total_price,
|
||||
asking_price=ad.asking_price,
|
||||
sale_status=None,
|
||||
)
|
||||
if changed:
|
||||
logger.debug("finn_ad %s updated -- invalidating analysis cache", finnkode)
|
||||
invalidate_analysis(conn, finnkode)
|
||||
@@ -118,10 +135,12 @@ async def get_or_fetch_eiendom_unit(
|
||||
the DB row is not updated (analysis_cache stays valid).
|
||||
"""
|
||||
conn = init_db(FINN_CACHE_PATH)
|
||||
# Convert structural TTL from days to hours
|
||||
ttl_hours = EIENDOM_NO_CACHE_TTL_STRUCTURAL_DAYS * 24
|
||||
unit = (
|
||||
None
|
||||
if force_refresh
|
||||
else get_cached_eiendom_unit(conn, unit_code, ttl_hours=24)
|
||||
else get_cached_eiendom_unit(conn, unit_code, ttl_hours=ttl_hours)
|
||||
)
|
||||
if unit is not None:
|
||||
return unit
|
||||
@@ -157,8 +176,10 @@ async def get_or_fetch_similar_units(
|
||||
return []
|
||||
|
||||
if not force_refresh:
|
||||
# Convert similar units TTL from days to hours
|
||||
ttl_hours = EIENDOM_NO_CACHE_TTL_SIMILAR_UNITS_DAYS * 24
|
||||
cached_similar = get_cached_similar_units(
|
||||
conn, unit_code, listing_status, ttl_hours=EIENDOM_NO_CACHE_TTL_HOURS
|
||||
conn, unit_code, listing_status, ttl_hours=ttl_hours
|
||||
)
|
||||
if cached_similar:
|
||||
logger.debug(
|
||||
|
||||
Reference in New Issue
Block a user