Skip to content

FetchPolicy.can_skip - #94

Merged
koenvo merged 4 commits into
mainfrom
feat/fetch-policy-can-skip
Aug 12, 2026
Merged

FetchPolicy.can_skip#94
koenvo merged 4 commits into
mainfrom
feat/fetch-policy-can-skip

Conversation

@koenvo

@koenvo koenvo commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

FetchPolicy operates on a fully loaded Dataset. This works fine until we have to check 200k+ datasets for each run. In certain cases with more complex FetchPolicies - like "fetch every 2 weeks" - we will check all datasets.

This PR introduces a can_skip method in FetchPolicy which gets a summary of each dataset instead of the full loaded Dataset. The summary is cheap to produce, and works like a bloom-filter: the method will return True when it's certain the dataset can be skipped and a non-True value when the full Dataset needs to be loaded.

koenvo added 3 commits August 12, 2026 10:47
can_skip is a cheap, one-sided pre-check (bloom-filter style): a policy may
return True only when it is certain, from a lightweight per-dataset summary,
that an existing dataset is up-to-date. The engine then skips it without loading
the full Dataset graph and without reaching should_refetch. Returning False
means "unknown" -> fall through to the authoritative path. Base FetchPolicy
returns False, so the hook is additive and non-breaking.

Red test asserts that, on a second run, can_skip=True skips the fetch (loader
never runs) and short-circuits before should_refetch. A regression guard asserts
the base policy still reaches should_refetch and refetches (can_skip=False).

Implementation (summary type + get_dataset_summary_map + the hook + engine call)
follows.

Claude-Session: https://claude.ai/code/session_01B5EfLJqoafjW1FhvkxGSmg
Turns the engine's inline timestamp pre-check into a single, overridable policy
hook so a policy can skip an up-to-date dataset without loading the full
dataset+revision+file graph or reaching should_refetch.

- DatasetSummary (+ DatasetSummaryMap): lightweight per-dataset projection
  (last_modified, current revision created_at/state, has_revisions).
- DatasetRepository.get_dataset_summary_map + SqlAlchemy implementation: one
  grouped "latest revision per dataset" query (portable — no Postgres-only
  DISTINCT ON, no correlated subquery-in-join), restricted to the provider.
- FetchPolicy.can_skip(summary, dataset_resource) -> bool: base keeps the old
  timestamp behaviour (skip when stored is at least as new as every reported
  file), so this is additive and non-breaking. One-sided: True only when
  certain; False = fall through to the authoritative path.
- Engine: the inline last_modified pre-check is replaced by a single can_skip
  call (no duplicate pre-check logic); loader builds the summary map once per
  (provider, dataset_type).

Makes test_can_skip green; existing fast-skip/engine tests unchanged.

Claude-Session: https://claude.ai/code/session_01B5EfLJqoafjW1FhvkxGSmg
…-skip

# Conflicts:
#	ingestify/domain/models/dataset/dataset.py
#	ingestify/domain/models/ingestion/ingestion_job.py
@koenvo
koenvo force-pushed the feat/fetch-policy-can-skip branch from 05df951 to 2b9ef37 Compare August 12, 2026 09:38
get_dataset_summary_map carries last_modified too, so the old map and its
DatasetLastModifiedAtMap type alias are redundant. Drop the repository interface
method, the SqlAlchemy implementation, the DatasetStore delegation, and the type
alias; repoint the fast-skip test to get_dataset_summary_map.

Claude-Session: https://claude.ai/code/session_01B5EfLJqoafjW1FhvkxGSmg
@koenvo
koenvo merged commit 788a4ce into main Aug 12, 2026
13 checks passed
@koenvo
koenvo deleted the feat/fetch-policy-can-skip branch August 12, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant