Repository navigation
feat: track the images embedded in the texts of the locales - #2732
Merged
Merged
Conversation
[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>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 42 |
| Duplication | 1 |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
guidebook.image_embeds(document_locale_id,image_id,document_id,lang), migration31b82bbbcecb.ON DELETE CASCADE), so deleting a locale or a document cleans it, soft delete included.image_idis not a foreign key: an id that does not exist, is not an image or was deleted is a broken embed, found by joiningdocumentsat query time. A merged image still shows (its target), its embeds are kept as written.get_embedded_image_ids()collects the ids thatC2CImageBlockturns into images, so a tag the parser does not show (inside raw HTML, mid-line,Right,[IMG=) is not counted. Same fields ascook(). Ids above 2^31-1 are left out, ascook()does.create_new_version,update_version(locales whose text changed) andadd_unchanged_version. This covers creation, update, revert and restore of a document or a locale.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
Deploy
31b82bbbcecb.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