Skip to content

feat: track the images embedded in the texts of the locales - #2732

Merged
lbesson merged 1 commit into
masterfrom
feat/image-embeds
Nov 24, 2026
Merged

lbesson merged 1 commit into
masterfrom
feat/image-embeds

Conversation

@lbesson

@lbesson lbesson commented Nov 24, 2026

Copy link
Copy Markdown
Member

Documents show images in their text with [img=ID ...], without any association. So an image listed as an orphan (no association, moderation tab of #2671) may still be in use, and deleting it breaks the documents that embed it. Example: image 1854248, embedded in article 1063876, was deleted from the orphans tab.

This PR only records the embeds. The follow-ups (orphans tab showing "embedded in", a broken-embeds tab, a warning when an embedded image is deleted or unlinked) come later and read this table.

What it does

  • New table guidebook.image_embeds (document_locale_id, image_id, document_id, lang), migration 31b82bbbcecb.
    • Deleted with its locale (ON DELETE CASCADE), so deleting a locale or a document cleans it, soft delete included.
    • image_id is not a foreign key: an id that does not exist, is not an image or was deleted is a broken embed, found by joining documents at query time. A merged image still shows (its target), its embeds are kept as written.
  • The ids come from the markdown parser itself: get_embedded_image_ids() collects the ids that C2CImageBlock turns into images, so a tag the parser does not show (inside raw HTML, mid-line, Right, [IMG=) is not counted. Same fields as cook(). Ids above 2^31-1 are left out, as cook() does.
  • Filled when a version is written: create_new_version, update_version (locales whose text changed) and add_unchanged_version. This covers creation, update, revert and restore of a document or a locale.
  • Script rebuild_image_embeds <ini> fills the table from the current texts (the migration creates it empty, so that the parser is not frozen into a migration). It can run while the API runs, and can repair the table later.

Numbers

  • 2018 dump: rebuild in 34 s, 12,739 locales read, 18,475 embeds.
  • Production (read-only queries): 24,091 embeds of 16,257 images in 12,439 documents. Broken: 61 ids that do not exist, 10 soft-deleted images, 13 ids of other document types. 26 embeds of 18 orphan images.

Deploy

  1. Migration 31b82bbbcecb.
  2. API.
  3. rebuild_image_embeds production.ini.

Tests

Parser cases, the samples of the img tag tests against parse_code, the fields read, and creation, update, new locale, revert, delete and restore of a locale or a document, and the rebuild. Full suite 2660 passed locally.

🤖 Generated with Claude Code

[img=ID] tags show an image without any association, so an orphan image
may still be in use. Table guidebook.image_embeds (locale, image id) is
filled when a version is written (creation, update, revert, restore),
from the ids the markdown parser itself turns into images, and removed
with the locale. Broken embeds and merged images are found at query
time. Script rebuild_image_embeds fills it after the migration (34 s on
the 2018 dump) and can repair it later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 42 complexity · 1 duplication

Metric Results
Complexity 42
Duplication 1

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@lbesson
lbesson merged commit 8903b46 into master Nov 24, 2026
7 checks passed
@lbesson
lbesson deleted the feat/image-embeds branch November 24, 2026 12:33
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