Avoid rewriting warm extraction cache
This commit is contained in:
parent
4a8980110d
commit
9fcafc290c
2 changed files with 21 additions and 18 deletions
|
|
@ -483,14 +483,7 @@ class AdapterProject:
|
||||||
if source.source_id in invalidated:
|
if source.source_id in invalidated:
|
||||||
contribution = loader.extract_source(source)
|
contribution = loader.extract_source(source)
|
||||||
reparsed.append(source.source_id)
|
reparsed.append(source.source_id)
|
||||||
else:
|
cache_record = CachedSource(
|
||||||
record = cached[source.source_id]
|
|
||||||
contribution = source_projection(record.payload)
|
|
||||||
hits.append(source.source_id)
|
|
||||||
validate_source_projection(source, contribution)
|
|
||||||
contributions.append(contribution)
|
|
||||||
cache_records.append(
|
|
||||||
CachedSource(
|
|
||||||
source_id=source.source_id,
|
source_id=source.source_id,
|
||||||
source_path=source.source_path,
|
source_path=source.source_path,
|
||||||
fingerprint=source.fingerprint,
|
fingerprint=source.fingerprint,
|
||||||
|
|
@ -498,7 +491,13 @@ class AdapterProject:
|
||||||
dependencies=source.dependencies,
|
dependencies=source.dependencies,
|
||||||
payload=source_payload(contribution),
|
payload=source_payload(contribution),
|
||||||
)
|
)
|
||||||
)
|
else:
|
||||||
|
cache_record = cached[source.source_id]
|
||||||
|
contribution = source_projection(cache_record.payload)
|
||||||
|
hits.append(source.source_id)
|
||||||
|
validate_source_projection(source, contribution)
|
||||||
|
contributions.append(contribution)
|
||||||
|
cache_records.append(cache_record)
|
||||||
projection = AdapterProjection(
|
projection = AdapterProjection(
|
||||||
project_id=manifest.project_id,
|
project_id=manifest.project_id,
|
||||||
title=manifest.title,
|
title=manifest.title,
|
||||||
|
|
@ -542,15 +541,16 @@ class AdapterProject:
|
||||||
raise DocForgeError(
|
raise DocForgeError(
|
||||||
"source_changed", "Adapter sources changed during incremental extraction"
|
"source_changed", "Adapter sources changed during incremental extraction"
|
||||||
)
|
)
|
||||||
write_extraction_cache(
|
if cache is None or invalidated or deleted:
|
||||||
self._cache_path,
|
write_extraction_cache(
|
||||||
ExtractionCache(
|
self._cache_path,
|
||||||
project_id=manifest.project_id,
|
ExtractionCache(
|
||||||
adapter_id=manifest.adapter_id,
|
project_id=manifest.project_id,
|
||||||
adapter_version=manifest.adapter_version,
|
adapter_id=manifest.adapter_id,
|
||||||
sources=tuple(cache_records),
|
adapter_version=manifest.adapter_version,
|
||||||
),
|
sources=tuple(cache_records),
|
||||||
)
|
),
|
||||||
|
)
|
||||||
self._last_logic = logic_projections
|
self._last_logic = logic_projections
|
||||||
self._last_build_report = {
|
self._last_build_report = {
|
||||||
"mode": "incremental",
|
"mode": "incremental",
|
||||||
|
|
|
||||||
|
|
@ -303,11 +303,14 @@ class AdapterContractTests(unittest.TestCase):
|
||||||
self.assertEqual(2, first["build"]["reparsed_sources"])
|
self.assertEqual(2, first["build"]["reparsed_sources"])
|
||||||
self.assertEqual(0, first["build"]["cache_hits"])
|
self.assertEqual(0, first["build"]["cache_hits"])
|
||||||
loader.extract_calls.clear()
|
loader.extract_calls.clear()
|
||||||
|
cache_path = root / ".cache" / "incremental" / "extractions.json"
|
||||||
|
cache_modified = cache_path.stat().st_mtime_ns
|
||||||
|
|
||||||
second = index.build()
|
second = index.build()
|
||||||
self.assertEqual([], loader.extract_calls)
|
self.assertEqual([], loader.extract_calls)
|
||||||
self.assertEqual(0, second["build"]["reparsed_sources"])
|
self.assertEqual(0, second["build"]["reparsed_sources"])
|
||||||
self.assertEqual(2, second["build"]["cache_hits"])
|
self.assertEqual(2, second["build"]["cache_hits"])
|
||||||
|
self.assertEqual(cache_modified, cache_path.stat().st_mtime_ns)
|
||||||
|
|
||||||
loader.sources["guide.foundation"] = "Changed foundation."
|
loader.sources["guide.foundation"] = "Changed foundation."
|
||||||
loader.extract_calls.clear()
|
loader.extract_calls.clear()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue