Repository navigation
Download icon sets on demand instead of shipping them in the ZIP - #211
Draft
Contributolo wants to merge 2 commits into
Draft
Contributolo wants to merge 2 commits into
Contributolo wants to merge 2 commits into
Conversation
The icon picker and bs_render_icon() share one lookup: a set stored in wp-content/blockstudio/icons wins, the bundled set is the fallback. Activation and updates copy the bundled sets there, so a later release can stop shipping them without existing sites losing an icon. The blockstudio/icons/dir filter moves the directory, and an empty string keeps the sets in the plugin only.
The release ZIP ships a checksum per icon set and no set. A set is downloaded from the release of the installed version when its picker first asks for it, and by WP-Cron when a render or an update finds it missing. Rendering never waits for the network, a download that does not match its checksum is discarded, and a failed download shows an admin notice and is retried hourly. The sets are built as release assets next to blockstudio.zip.
This branch has not been deployed
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.
Closes #8. This is the second step after #210 and contains its commit, so please look at #210 first; only the last commit is new. It is a draft because it changes the release workflow, which I cannot run from a fork.
Result
The release ZIP no longer contains the 44 icon sets (22 MB unpacked, 13.4 MB ZIP to about 7.6 MB). It ships
includes/icons.jsonwith one SHA-256 checksum per set. A set is downloaded intowp-content/blockstudio/iconswhen it is needed.How a set gets there
Rest::icons()downloads a missing set in that request, stores it and returns it. The picker and its retry on refocus are unchanged.bs_render_icon()never makes a request. An icon of a set that is not stored renders nothing, as an unknown set does today, and the set is scheduled for WP-Cron (blockstudio/icons/fetch), so templates that callbs_render_icon()with a set nobody picked in the editor heal on the next request.https://github.com/inline0/blockstudio/releases/download/v<version>/blockstudio-icons-<set>.json. Only names from the checksum file are requested, the response is streamed to a temporary file, and it is kept only if it matches its checksum.When the download fails
The background run stops at the first failure, shows a warning notice to administrators and retries hourly, so a server without access to GitHub makes one request per hour. During that hour render misses schedule nothing. Two ways out, both documented:
blockstudio/icons/urlpoints the download at another host, and an emptyblockstudio/icons/dir(from #210) turns storing and downloading off.Build and release
ships()inscripts/build-release.tsexcludesincludes/icons/. The build copies the sets tobuild/icons/blockstudio-icons-<set>.json.release.ymluploadsbuild/icons/*.jsonnext toblockstudio.zip. Not run, see above.dist.ymlrequiresincludes/icons.jsonin the ZIP and fails ifincludes/iconsleaked.generate-icons.tswrites the checksum file. The committed one was computed from the committed sets, and a unit test fails when the two differ.Source checkouts and Composer installs still contain the sets and download nothing. I did not add
export-ignorefor them, so Composer archives are unchanged. Say so if you want them slimmed too.Open points
.pot,de_DEandde_DE_formal; the other locales are untouched andi18n:checkwill report them until the release fills them.Tests
tests/unit/icons/IconFetchTest.php(12 tests, HTTP faked throughpre_http_request): checksum file matches every committed set, picker download and second call without a request, URL filter, checksum mismatch discarded, failed response, set without checksum never requested, empty directory requests nothing, render miss schedules without a request and renders after the cron run, failure recorded with notice and hourly retry and cleared on success, update schedules missing sets, update with everything stored schedules nothing, first activation downloads nothing.Run locally in WordPress Playground:
tests/unit/icons(78),tests/unit/migrate(40),tests/unit/rest(25),tests/unit/i18n(13) pass.node --test scripts/tests/build.test.ts,npm run lint, the tooling typecheck andnpm run docs:checkpass, PHPCS and PHPStan are clean on the changed files. Not run: the full suites, E2E,npm run build:release, and a real download, since no release has the assets yet.