Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
better cache busting in the studio
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField committed Jun 19, 2024
1 parent 9b1063d commit 408ed99
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/editor/src/components/Editor2Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const EditorContainer = () => {
projectName.set(scene.project!)
sceneName.set(scene.key.split('/').pop() ?? null)
sceneAssetID.set(sceneQuery[0].id)
return setCurrentEditorScene(scene.key, scene.id as EntityUUID)
return setCurrentEditorScene(scene.url, scene.id as EntityUUID)
}, [sceneQuery[0]?.key])

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/components/EditorContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ const EditorContainer = () => {
projectName.set(scene.project!)
sceneName.set(scene.key.split('/').pop() ?? null)
sceneAssetID.set(sceneQuery[0].id)
return setCurrentEditorScene(scene.key, scene.id as EntityUUID)
return setCurrentEditorScene(scene.url, scene.id as EntityUUID)
}, [sceneQuery[0]?.key])

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/functions/sceneFunctions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const onNewScene = async (
}

export const setCurrentEditorScene = (sceneURL: string, uuid: EntityUUID) => {
const gltfEntity = GLTFSourceState.load(fileServer + '/' + sceneURL, uuid)
const gltfEntity = GLTFSourceState.load(sceneURL, uuid)
getMutableComponent(Engine.instance.viewerEntity, SceneComponent).children.merge([gltfEntity])
getMutableState(EditorState).rootEntity.set(gltfEntity)
return () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@ export const staticResourceDbToSchema = (rawData: StaticResourceDatabaseType): S
}
}

/**
* the first few characters of resources hashes are appended as a version identifier to allow for cache busting
*/

export const staticResourceResolver = resolve<StaticResourceType, HookContext>(
{
createdAt: virtual(async (staticResource) => fromDateTimeSql(staticResource.createdAt)),
updatedAt: virtual(async (staticResource) => fromDateTimeSql(staticResource.updatedAt)),
url: virtual(async (staticResource, context) => {
const storageProvider = getStorageProvider()
return storageProvider.getCachedURL(staticResource.key, context.params.isInternal) + '?v=' + staticResource.hash
return (
storageProvider.getCachedURL(staticResource.key, context.params.isInternal) +
'?hash=' +
staticResource.hash.slice(0, 6)
)
}),
thumbnailURL: virtual(async (staticResource, context) => {
if (!staticResource.thumbnailKey) return
Expand All @@ -80,11 +88,11 @@ export const staticResourceResolver = resolve<StaticResourceType, HookContext>(
key: staticResource.thumbnailKey
}
})
if (!thumbnailStaticResource.data.length) throw new Error('Thumbnail not found')
if (!thumbnailStaticResource.data.length) return
return (
storageProvider.getCachedURL(staticResource.thumbnailKey, context.params.isInternal) +
'?v=' +
thumbnailStaticResource.data[0].hash
'?hash=' +
thumbnailStaticResource.data[0].hash.slice(0, 6)
)
})
},
Expand Down

0 comments on commit 408ed99

Please sign in to comment.