Merge dev → main: per-post stdout diagnostics + post-field write DRY (#842/#753) #106
@@ -739,6 +739,29 @@ class Importer:
|
|||||||
self.session.commit()
|
self.session.commit()
|
||||||
return ImportResult(status="refreshed", image_id=existing.id)
|
return ImportResult(status="refreshed", image_id=existing.id)
|
||||||
|
|
||||||
|
def _apply_post_fields(self, post: Post, sd) -> None:
|
||||||
|
"""Write a parsed sidecar's post-level fields onto a Post — the SINGLE
|
||||||
|
predicate shared by BOTH ingest paths: the per-media path (_apply_sidecar)
|
||||||
|
and the post-record path (upsert_post_record). Fill-with-non-empty:
|
||||||
|
parse_sidecar yields None for empty values, so a None field is left
|
||||||
|
untouched (an empty feed body never wipes a populated one). raw_metadata +
|
||||||
|
external-link sync always run (latest snapshot). Keeping ONE copy stops
|
||||||
|
the two paths from diverging on how a post body/links get stored — they
|
||||||
|
were verbatim duplicates (#842 DRY pass; see [[feedback_preview_apply_parity]]).
|
||||||
|
"""
|
||||||
|
if sd.post_url is not None:
|
||||||
|
post.post_url = sd.post_url
|
||||||
|
if sd.post_title is not None:
|
||||||
|
post.post_title = sd.post_title
|
||||||
|
if sd.post_date is not None:
|
||||||
|
post.post_date = sd.post_date
|
||||||
|
if sd.description is not None:
|
||||||
|
post.description = sd.description
|
||||||
|
if sd.attachment_count is not None:
|
||||||
|
post.attachment_count = sd.attachment_count
|
||||||
|
post.raw_metadata = sd.raw
|
||||||
|
self._sync_external_links(post)
|
||||||
|
|
||||||
def upsert_post_record(
|
def upsert_post_record(
|
||||||
self, sidecar: Path, *, artist: Artist | None = None,
|
self, sidecar: Path, *, artist: Artist | None = None,
|
||||||
source: Source | None = None,
|
source: Source | None = None,
|
||||||
@@ -785,18 +808,7 @@ class Importer:
|
|||||||
)
|
)
|
||||||
if post.artist_id is None:
|
if post.artist_id is None:
|
||||||
post.artist_id = artist.id
|
post.artist_id = artist.id
|
||||||
if sd.post_url is not None:
|
self._apply_post_fields(post, sd)
|
||||||
post.post_url = sd.post_url
|
|
||||||
if sd.post_title is not None:
|
|
||||||
post.post_title = sd.post_title
|
|
||||||
if sd.post_date is not None:
|
|
||||||
post.post_date = sd.post_date
|
|
||||||
if sd.description is not None:
|
|
||||||
post.description = sd.description
|
|
||||||
if sd.attachment_count is not None:
|
|
||||||
post.attachment_count = sd.attachment_count
|
|
||||||
post.raw_metadata = sd.raw
|
|
||||||
self._sync_external_links(post)
|
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -1098,18 +1110,7 @@ class Importer:
|
|||||||
external_post_id=epid,
|
external_post_id=epid,
|
||||||
artist_id=artist.id,
|
artist_id=artist.id,
|
||||||
)
|
)
|
||||||
if sd.post_url is not None:
|
self._apply_post_fields(post, sd)
|
||||||
post.post_url = sd.post_url
|
|
||||||
if sd.post_title is not None:
|
|
||||||
post.post_title = sd.post_title
|
|
||||||
if sd.post_date is not None:
|
|
||||||
post.post_date = sd.post_date
|
|
||||||
if sd.description is not None:
|
|
||||||
post.description = sd.description
|
|
||||||
if sd.attachment_count is not None:
|
|
||||||
post.attachment_count = sd.attachment_count
|
|
||||||
post.raw_metadata = sd.raw
|
|
||||||
self._sync_external_links(post)
|
|
||||||
|
|
||||||
# Race-safe (image_record_id, post_id) upsert — mirrors the
|
# Race-safe (image_record_id, post_id) upsert — mirrors the
|
||||||
# _find_or_create_source/post savepoint pattern. The plain
|
# _find_or_create_source/post savepoint pattern. The plain
|
||||||
|
|||||||
Reference in New Issue
Block a user