Skip to content

Commit

Permalink
Remove local cache for vector search
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Sep 21, 2024
1 parent c6c1d93 commit 6853e94
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
4 changes: 0 additions & 4 deletions macrostrat_tileserver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from titiler.core.factory import TilerFactory
from pydantic_settings import SettingsConfigDict

from .vector_search import on_startup
from .cached_tiler import CachedStoredFunction, CachedVectorTilerFactory
from .function_layer import StoredFunction
from .image_tiles import MapnikLayerFactory, prepare_image_tile_subsystem
Expand Down Expand Up @@ -64,9 +63,6 @@ async def startup_event():
setup_stderr_logs("macrostrat_tileserver", "timvt")
await connect_to_db(app, db_settings)

# Truncate the search term index
await on_startup(app)

# Apply fixtures
# apply_fixtures(db_settings.database_url)

Expand Down
42 changes: 0 additions & 42 deletions macrostrat_tileserver/vector_search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@
log = get_logger(__name__)


async def on_startup(app):

if not hasattr(app.state, "settings"):
app.state.settings = {}

# This doesn't work with multiple pods
# try:
# stmt = get_sql(__here__ / "queries" / "startup.sql")
# # Truncate the search term cache as we may have changed the math
# async with pool.acquire() as con:
# await con.execute(stmt)
# except Exception as e:
# log.error("Error refreshing vector search term cache")
# app.state.settings["vector_search_error"] = str(e)


router = APIRouter()

__here__ = Path(__file__).parent
Expand All @@ -48,10 +32,6 @@ async def get_tile(
if not term:
raise ValueError("No term provided")

# make sure we're not in an error state
if "vector_search_error" in request.app.state.settings:
raise ValueError(request.app.state.settings["vector_search_error"])

model_name = standardize_model_name(model)

term_id = await get_search_term_id(pool, term, model_name)
Expand All @@ -78,31 +58,9 @@ async def get_tile(
return VectorTileResponse(units_)


class TermIndex(dict):
index: ContextVar[dict] = ContextVar("term_index", default={})

def get_term(self, model, term) -> int:
return self.index.get().get(model, {}).get(term)

def set_term(self, model: str, term: str, term_id: int):
self.index.set(
{
**self.index.get(),
model: {**self.index.get().get(model, {}), term: term_id},
}
)


_index = TermIndex()


async def get_search_term_id(pool, term, model) -> int:
"""Get the ID of a search term from the database, or create it if it doesn't exist."""

term_id = _index.get_term(model, term)
if term_id:
return term_id

# Check the database to see if the term exists
term_id = await fetchval(
pool,
Expand Down

0 comments on commit 6853e94

Please sign in to comment.