Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cubedash/index/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from datacube.index import Index
from datacube.model import Dataset, MetadataType, Product, Range
from datacube.model.fields import Field
from sqlalchemy import Result, Row, Select
from sqlalchemy import CursorResult, Result, Row, Select
from sqlalchemy.sql import ColumnElement
from sqlalchemy.sql.elements import ClauseElement, Label

Expand Down Expand Up @@ -150,10 +150,10 @@ def upsert_product_record(
) -> tuple[int, datetime]: ...

@abstractmethod
def upsert_product_regions(self, product_id: int) -> Result: ...
def upsert_product_regions(self, product_id: int) -> CursorResult: ...

@abstractmethod
def delete_product_empty_regions(self, product_id: int) -> Result: ...
def delete_product_empty_regions(self, product_id: int) -> CursorResult: ...

@abstractmethod
def product_region_summary(self, product_id: int) -> Result: ...
Expand Down
5 changes: 3 additions & 2 deletions cubedash/index/postgis/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from geoalchemy2.shape import from_shape
from sqlalchemy import (
ClauseElement,
CursorResult,
Integer,
Label,
Result,
Expand Down Expand Up @@ -300,7 +301,7 @@ def product_summary_cols(self, product_name: str) -> Row:
).fetchone()

@override
def upsert_product_regions(self, product_id: int) -> Result:
def upsert_product_regions(self, product_id: int) -> CursorResult:
# add new regions row and/or update existing regions based on dataset_spatial
with self.index._active_connection() as conn:
return conn.execute(
Expand Down Expand Up @@ -336,7 +337,7 @@ def upsert_product_regions(self, product_id: int) -> Result:
)

@override
def delete_product_empty_regions(self, product_id: int) -> Result:
def delete_product_empty_regions(self, product_id: int) -> CursorResult:
with self.index._active_connection() as conn:
return conn.execute(
text(f"""
Expand Down
5 changes: 3 additions & 2 deletions cubedash/index/postgres/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from geoalchemy2.shape import from_shape
from sqlalchemy import (
ClauseElement,
CursorResult,
Integer,
Label,
Result,
Expand Down Expand Up @@ -316,7 +317,7 @@ def product_summary_cols(self, product_name: str) -> Row:
).fetchone()

@override
def upsert_product_regions(self, product_id: int) -> Result:
def upsert_product_regions(self, product_id: int) -> CursorResult:
# add new regions row and/or update existing regions based on dataset_spatial
with self.index._active_connection() as conn:
return conn.execute(
Expand Down Expand Up @@ -352,7 +353,7 @@ def upsert_product_regions(self, product_id: int) -> Result:
)

@override
def delete_product_empty_regions(self, product_id: int) -> Result:
def delete_product_empty_regions(self, product_id: int) -> CursorResult:
with self.index._active_connection() as conn:
return conn.execute(
text(f"""
Expand Down
4 changes: 3 additions & 1 deletion cubedash/summary/_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import warnings
from collections import Counter
from collections.abc import Sequence
Expand Down Expand Up @@ -126,7 +128,7 @@ def add_periods(
cls,
product_name: str,
product_refresh_time: datetime,
periods: Iterable["TimePeriodOverview"],
periods: Iterable["TimePeriodOverview" | None],
# This is in CRS units. Albers, so 1KM.
# Lower value will have a more accurate footprint and much larger page load times.
footprint_tolerance: float = 1000.0,
Expand Down
13 changes: 7 additions & 6 deletions cubedash/summary/_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ def _persist_product_extent(self, product: ProductSummary) -> None:
)

row = self.e_index.upsert_product_record(product.name, fields)
self._product.cache_clear()
self._product.cache_clear() # type: ignore[attr-defined]
product_id, last_refresh_time = row

product.id_ = product_id
Expand Down Expand Up @@ -930,7 +930,7 @@ def _get_field_exprs(
for value in self.e_index.get_mutable_dataset_search_fields(
product.metadata_type
).values():
expr = value.alchemy_expression
expr = value.alchemy_expression # type: ignore[attr-defined]
if hasattr(value, "offset"):
field_exprs[value.offset[-1]] = expr
field_exprs[value.name] = expr
Expand Down Expand Up @@ -1386,12 +1386,13 @@ def _database_time_now(self) -> datetime:
"""
return self.e_index.execute_query(select(func.now())).scalar()

def _newest_known_dataset_addition_time(self, product_name: str) -> datetime:
def _newest_known_dataset_addition_time(self, product_name: str) -> datetime | None:
"""
Of all the datasets that are present in Explorer's own tables, when
was the most recent one indexed to ODC?
"""
return self.e_index.latest_dataset_added_time(self.get_product(product_name).id)
id_ = self.get_product(product_name).id
return None if id_ is None else self.e_index.latest_dataset_added_time(id_)

def _mark_product_refresh_completed(
self, product: ProductSummary, refresh_timestamp: datetime
Expand All @@ -1403,7 +1404,7 @@ def _mark_product_refresh_completed(
"""
assert product.id_ is not None
self.e_index.update_product_refresh_timestamp(product.id_, refresh_timestamp)
self._product.cache_clear()
self._product.cache_clear() # type: ignore[attr-defined]

def list_complete_products(self) -> list[str]:
"""
Expand Down Expand Up @@ -1563,7 +1564,7 @@ def _summary_from_row(
product_refresh_time=res["product_refresh_time"],
# When this summary was last generated
summary_gen_time=res["generation_time"],
crses=set(res["crses"]) if res["crses"] is not None else None,
crses=set(crses) if (crses := res["crses"]) is not None else set(),
)


Expand Down