Fixes for local github cache expiration, projects loading while offline#11342
Fixes for local github cache expiration, projects loading while offline#11342jwunderl wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
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, andloadTutorialMarkdown. - 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
backupScriptTextthroughIGithubDb.loadPackageAsync,downloadPackageAsync, andcacheProjectDependenciesAsync(now recursive with acheckedset), withCachedPackage.backupCopyto 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. |
|
|
||
| export interface CachedPackage { | ||
| files: Map<string>; | ||
| backupCopy?: boolean; |
There was a problem hiding this comment.
what is the purpose of this property?
|
|
||
| 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> { |
There was a problem hiding this comment.
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
|
|
||
| // cache! | ||
| this.packages[key] = current; | ||
| return U.clone(current); |
There was a problem hiding this comment.
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.
| export function stringifyHexInfoForCache(hexInfo: pxtc.HexInfo) { | ||
| if (!hexInfo?.hex) return undefined; | ||
|
|
||
| const cachedMeta = U.clone(hexInfo); |
There was a problem hiding this comment.
again, prefer to not use clone if possible
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