fix(posts): make HasImage raise-only to stop rescan churn

TraverseDirectory's two AddPost call sites pass opposite hasImage values
for one post (duplicate _N folders, /blog/private bodies on own-blog
reblogs), and --ingest does the same across duplicate files. The
overwrite flipped the flag 0->1->0 and bumped DateModified every pass.
UpdatePost, AddPost's fallback and UpsertPostFromTextFile now only raise
HasImage, matching ByLikes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
jimandClaude Opus 5.5 committed 2026-10-02 09:15:42 -05:00
1 parent 5af284a49f
commit e18fb5ca10
3 files changed
+30 -13

No files matched your search

+19 -7
View File
@@ -161,7 +161,7 @@ though the true content never changes.
make the statement fire at all, and `DateModified` stays put
- Deliberately narrow: only the literal `"."` is the sentinel. An explicit empty string from
a real record still overwrites, same as before this fix. `postID`, `BlogName`, `hasImage`,
`ByLikes` are not part of this convention and are unaffected
`ByLikes` are not part of this convention; the two flags are raise-only instead (below)
- If a new content field is added to `Posts`/`UpdatePost`, decide explicitly whether its
source can legitimately supply `"."` as "field absent" before deciding whether it needs
the same `CASE` treatment — don't assume every column needs it
@@ -189,12 +189,24 @@ lands last for a given `(BlogName, PostID)` is arbitrary.
sentinel. `G()` already distinguishes this from "present but blank" — a dictionary miss is
`null`, an empty value after the prefix is `""` — so an explicitly blank field still
overwrites
- `HasImage` is **not** guarded and remains a known gap: `IngestMode` always computes a
concrete `bool` (defaulting `false` when a file has no `Has Image:` line), so there is no
way for this function to tell "this format says no image" from "this format doesn't report
it at all" without changing the parameter to `bool?` and threading that through
`IngestMode`/`LegacyPostsDbImporter`. Fix this the same way if `--ingest` is observed
downgrading a post's `HasImage` from `1` to `0`
- `HasImage` cannot use the sentinel: `IngestMode` always computes a concrete `bool`
(defaulting `false` when a file has no `Has Image:` line), so this function cannot tell
"this format says no image" from "this format doesn't report it". It is raise-only instead
(below), which settles the same duplicate-file case without threading a `bool?` through
**`Posts.HasImage` is raise-only (since 2026-10-02).** Every automated writer (`UpdatePost`,
`AddPost`'s fallback, `UpsertPostFromTextFile`) sets `HasImage = MAX(IFNULL(HasImage, 0),
@hasImage)` and guards the change-detection with `(@hasImage = 1 AND IFNULL(HasImage, 0) = 0)`,
the same shape `ByLikes` already used. No source sends a trustworthy "no image": a format
without a downloaded-files or `Has Image:` line reports `false` for a post that has one.
- `TraverseDirectory`'s two `AddPost` call sites pass opposite values for one post — a
duplicate `_N` folder with and without a downloaded-files line, or a record with no
downloads whose body has `/blog/private` and whose `Reblog url` matches `ContainsList`.
Overwriting flipped the flag `0→1→0` on every no-argument scan, bumping `DateModified`
twice per pass and leaving whichever value ran last
- Lowering `HasImage` is a manual correction. `UpdatePostContentFields` (CorrectMode, restoring
from a `.bak`) still overwrites it, and that is deliberate
### Testing
- No existing test suite; use xUnit if adding tests