Skip to content

Commit

Permalink
⚡️ Unused assets query performance (#1324)
Browse files Browse the repository at this point in the history
  • Loading branch information
padms committed Jan 13, 2023
1 parent f194f97 commit 4bc4d64
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
6 changes: 6 additions & 0 deletions studio/src/lib/structure/items/AssetLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const assetLibraryItems = [
.icon(TagMoreIcon)
.child(S.documentTypeList('assetTag').id('manageAssetTags').title('Manage asset tags')),
Flags.IS_DEV && S.divider(),
Flags.IS_DEV &&
S.listItem()
.title('Video Assets')
.icon(() => EdsIcon(play_circle_outlined))
.child(S.documentTypeList('videoFile').id('videoFiles').title('Video Files')),
Flags.IS_DEV && S.divider(),
Flags.IS_DEV && UnusedAssetFilters(),
].filter((e) => e)

Expand Down
64 changes: 36 additions & 28 deletions studio/src/lib/structure/items/UnusedAssetFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,46 @@ export const UnusedAssetFilters = () =>
.title('Unused files')
.icon()
.child(S.list('unusedAssets').title('Unused Files').items(unusedTypesListItems))
.id('unusedFiles')

const getUnusedPublishedAssets = (docType) =>
S.documentTypeList(docType)
.apiVersion('2023-01-13')
.filter(
/* groq */ ` _type in [$docType] && (
(!(_id in path("drafts.**"))&& count(*[references(^._id)]) == 0)
)`,
)
.params({ docType })
.id(`unusedPublishedAssets-${docType}`)

const getUnpublishedDraftAssets = (docType) =>
S.documentTypeList(docType)
.apiVersion('2023-01-13')
.filter(
/* groq */ ` _type in [$docType] && (
(_id in path("drafts.**") && count(*[^._id == "drafts." + _id]) == 0)
)`,
)
.params({ docType })
.id(`unpublishedDrafts-${docType}`)

const unusedTypesListItems = [
S.listItem().icon(FileIcon).child(getUnpublishedDraftAssets('assetFile')).id('draftAssets').title('Draft Assets'),
S.listItem()
.title('Unused asset files')
.icon(FileIcon)
.child(
S.documentTypeList('assetFile')
.apiVersion('2022-05-12')
.filter(
/* groq */ ` _type in ["assetFile"] && (
(!(_id in path("drafts.**"))&& count(*[references(^._id)]) == 0)
||
(_id in path("drafts.**") && count(*[^._id == "drafts." + _id]) == 0)
)`,
)
.id('allFiles')
.title('All unused files'),
),
.child(getUnusedPublishedAssets('assetFile'))
.id('publishedAssets')
.title('Published Assets'),
S.divider(),
S.listItem()
.icon(() => EdsIcon(play_circle_outlined))
.child(getUnpublishedDraftAssets('videoFile'))
.id('draftVideos')
.title('Draft Videos'),
S.listItem()
.title('Unused video assets')
.icon(() => EdsIcon(play_circle_outlined))
.child(
S.documentTypeList('videoFile')
.apiVersion('2022-05-12')
.filter(
/* groq */ ` _type in ["videoFile"] && (
(!(_id in path("drafts.**"))&& count(*[references(^._id)]) == 0)
||
(_id in path("drafts.**") && count(*[^._id == "drafts." + _id]) == 0)
)`,
)
.id('videoFiles')
.title('Video Files'),
),
.child(getUnusedPublishedAssets('videoFile'))
.id('publishedVideos')
.title('Published Videos'),
]

0 comments on commit 4bc4d64

Please sign in to comment.