Skip to content

Commit

Permalink
Refactor surface router to use async Redis client
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdp committed Nov 22, 2024
1 parent a0c73df commit 59c5ec8
Showing 1 changed file with 18 additions and 33 deletions.
51 changes: 18 additions & 33 deletions backend_py/primary/primary/routers/surface/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,34 @@

from primary.services.sumo_access.case_inspector import CaseInspector
from primary.services.sumo_access.surface_access import SurfaceAccess
from primary.services.smda_access.stratigraphy_access import (
StratigraphyAccess,
StratigraphicUnit,
)
from primary.services.smda_access.stratigraphy_utils import (
sort_stratigraphic_names_by_hierarchy,
)
from primary.services.smda_access.mocked_drogon_smda_access import (
_mocked_stratigraphy_access,
)
from primary.services.smda_access.stratigraphy_access import StratigraphyAccess, StratigraphicUnit
from primary.services.smda_access.stratigraphy_utils import sort_stratigraphic_names_by_hierarchy
from primary.services.smda_access.mocked_drogon_smda_access import _mocked_stratigraphy_access
from primary.services.utils.statistic_function import StatisticFunction
from primary.services.utils.surface_intersect_with_polyline import (
intersect_surface_with_polyline,
)
from primary.services.utils.surface_intersect_with_polyline import intersect_surface_with_polyline
from primary.services.utils.authenticated_user import AuthenticatedUser
from primary.auth.auth_helper import AuthHelper
from primary.services.surface_query_service.surface_query_service import (
batch_sample_surface_in_points_async,
)
from primary.services.surface_query_service.surface_query_service import (
RealizationSampleResult,
)
from primary.services.surface_query_service.surface_query_service import batch_sample_surface_in_points_async
from primary.services.surface_query_service.surface_query_service import RealizationSampleResult
from primary.utils.response_perf_metrics import ResponsePerfMetrics

from . import converters
from . import schemas
from . import dependencies

from .surface_address import (
RealizationSurfaceAddress,
ObservedSurfaceAddress,
StatisticalSurfaceAddress,
)
from .surface_address import RealizationSurfaceAddress, ObservedSurfaceAddress, StatisticalSurfaceAddress
from .surface_address import decode_surf_addr_str

import redis
#import redis
import redis.asyncio as redis

from primary import config
from fastapi_cache import FastAPICache
from fastapi import FastAPI
from typing import AsyncIterator
from fastapi_cache.backends.redis import RedisBackend
from contextlib import asynccontextmanager
from fastapi_cache.decorator import cache
# from fastapi_cache import FastAPICache
# from fastapi import FastAPI
# from typing import AsyncIterator
# from fastapi_cache.backends.redis import RedisBackend
# from contextlib import asynccontextmanager
# from fastapi_cache.decorator import cache
import json
from pydantic import TypeAdapter
import hashlib
Expand Down Expand Up @@ -362,7 +347,7 @@ def compute_hash(numbers: List[int]) -> str:
perf_metrics.record_lap("build-key")


cached_data = redis_client.get(my_cache_key)
cached_data = await redis_client.get(my_cache_key)
perf_metrics.record_lap("cache-lookup")

if cached_data:
Expand Down Expand Up @@ -398,7 +383,7 @@ def compute_hash(numbers: List[int]) -> str:
)
perf_metrics.record_lap("convert")

redis_client.set(my_cache_key, ta.dump_json(intersections))
await redis_client.set(my_cache_key, ta.dump_json(intersections))
perf_metrics.record_lap("write-cache")

LOGGER.info(f"Sampled surface in points in: {perf_metrics.to_string()}")
Expand Down

0 comments on commit 59c5ec8

Please sign in to comment.