Skip to content

Fixes for local github cache expiration, projects loading while offline#11342

Open
jwunderl wants to merge 4 commits into
masterfrom
dev/jwunderl/caching-woes
Open

Fixes for local github cache expiration, projects loading while offline#11342
jwunderl wants to merge 4 commits into
masterfrom
dev/jwunderl/caching-woes

Conversation

@jwunderl

@jwunderl jwunderl commented Jun 1, 2026

Copy link
Copy Markdown
Member

Fix microsoft/pxt-microbit#6686 in first commit
Should be a fix for microsoft/pxt-microbit#5047 in follow up two commits, which are basically a refinement of my very old draft fix #9529

in both cases i'm gonna need to test this a bit; i'll test the first issue before merging at least.

first commit: fix caching so that we do not purge everything > 60 minutes old on load from github db, and fall back to cache if expired but network unavailable.

follow up 2 commits: patch in catching info for extensions to generated hexfiles, so that they can be used as a backup if available when loading file with extensions while offline

build: https://makecode.microbit.org/app/97d79fec959f349ff930dc28daa1c7bde82c41a7-f2529e968c

@jwunderl jwunderl requested review from a team, Copilot and riknoll June 1, 2026 17:41
@jwunderl jwunderl changed the title Dev/jwunderl/caching woes Fixes for local github cache expiration, projects loading while offline Jun 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes two offline-related issues: (1) the local GitHub DB was purging all cached package/config/tutorial entries after 60 minutes, and (2) projects with GitHub extensions couldn't be opened offline. The first commit narrows expiration purging to tutorial entries and falls back to cached data when the network is unavailable. The follow-up commits embed packaged copies of external (GitHub/pub) extension files and target hex-info into generated hex files so they can be re-hydrated into IndexedDB on import when offline.

Changes:

  • Narrow GitHub IndexedDB cache expiration purge to tutorial entries; add offline-fallback paths in latestVersionAsync, loadPackageAsync, and loadTutorialMarkdown.
  • During native non-UF2 compile, embed _packaged-extensions.json (transitive github/pub dep files) and _packaged-ext-info.json (per-target hex info) into published files; on install, re-populate script/hex-info caches and pass backup files into the GitHub package download path.
  • Plumb optional backupScriptText through IGithubDb.loadPackageAsync, downloadPackageAsync, and cacheProjectDependenciesAsync (now recursive with a checked set), with CachedPackage.backupCopy to mark fallback entries.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
webapp/src/idbworkspace.ts Restrict expiration purge to tutorial entries; add offline cache-hit fallbacks for latest version/load package/tutorial; new loadPackageFromMemoryAsync helper using backupScriptText.
webapp/src/workspace.ts On install, extract PACKAGED_EXTENSIONS and PACKAGED_EXT_INFO from imported files and seed script cache and hex-info host cache before caching project deps.
pxtlib/github.ts Add backupCopy/backupScriptText plumbing; refactor githubLoadPackageAsync to async/await with backup fallback; recursive cacheProjectDependenciesCoreAsync with dedupe.
pxtlib/package.ts Make filesToBePublishedAsync async and optionally bundle external extensions; add packagedExternalExtensions and packagedExtensionHexInfo; embed both into compiled files for non-UF2 native targets.
pxtlib/cpp.ts Extract stringifyHexInfoForCache and add storeHexInfoCacheEntryAsync for reuse from workspace import.
pxtlib/main.ts Add PACKAGED_EXTENSIONS and PACKAGED_EXT_INFO filename constants.
pxtcompiler/simpledriver.ts Forward backupScriptText through loadPackageAsync.
cli/cli.ts Forward backupScriptText through FileGithubDb.loadPackageAsync.

Comment thread pxtlib/github.ts Outdated

export interface CachedPackage {
files: Map<string>;
backupCopy?: boolean;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of this property?

Comment thread cli/cli.ts Outdated

loadPackageAsync(repopath: string, tag: string): Promise<pxt.github.CachedPackage> {
return this.loadAsync(repopath, tag, "pkg", (r, t) => this.db.loadPackageAsync(r, t));
loadPackageAsync(repopath: string, tag: string, backupScriptText?: pxt.Map<string>): Promise<pxt.github.CachedPackage> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling this backupScriptText is confusing to me... maybe localCache? inMemoryCache? or even fallbackCache? same applies to all the other places where backup is used

i typically read backup as a verb, so this kept reading to me as an optional boolean

Comment thread pxtlib/github.ts Outdated

// cache!
this.packages[key] = current;
return U.clone(current);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know this isn't changed code, but best not to use clone here. would be better to just use

return {
  files: {
    ...current.files
  }
}

iirc clone just calls JSON.stringify and JSON.parse, which is, uh, not the most memory efficient way of doing things especially when we already have a problem with too big scripts.

Comment thread pxtlib/cpp.ts Outdated
export function stringifyHexInfoForCache(hexInfo: pxtc.HexInfo) {
if (!hexInfo?.hex) return undefined;

const cachedMeta = U.clone(hexInfo);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, prefer to not use clone if possible

@jwunderl jwunderl requested a review from riknoll June 5, 2026 17:17
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.

Cached extensions are unavailable after an hour, for importing hex files while offline.

3 participants