Skip to content

Commit

Permalink
[C-4495] Fix hidden track albums (#8821)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Jun 13, 2024
1 parent e5c2536 commit e38ef5b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,33 +152,16 @@ export function* retrieveCollectionByPermalink(
) {
const {
fetchTracks = false,
requiresAllTracks = false,
forceRetrieveFromSource = false,
deleteExistingEntry
} = config ?? {}
// @ts-ignore retrieve should be refactored to ts first
const { entries, uids } = yield* call(retrieve, {
ids: [permalink],
selectFromCache: function* (permalinks: string[]) {
const cachedCollections = yield* select(
cacheCollectionsSelectors.getCollections,
{
permalinks
}
)
if (requiresAllTracks) {
const keys = Object.keys(cachedCollections) as unknown as number[]
keys.forEach((collectionId) => {
const fullTrackCount = cachedCollections[collectionId].track_count
const currentTrackCount =
cachedCollections[collectionId].tracks?.length ?? 0
if (currentTrackCount < fullTrackCount) {
// Remove the collection from the res so retrieve knows to get it from source
delete cachedCollections[collectionId]
}
})
}
return cachedCollections
return yield* select(cacheCollectionsSelectors.getCollections, {
permalinks
})
},
getEntriesTimestamp: selectEntriesTimestamp,
retrieveFromSource: function* (permalinks: string[]) {
Expand Down Expand Up @@ -228,10 +211,6 @@ export type RetrieveCollectionsConfig = {
fetchTracks?: boolean
// optional owner of collections to fetch (TODO: to be removed)
userId?: ID | null
/** whether or not fetching this collection requires it to have all its tracks.
* In the case where a collection is already cached with partial tracks, use this flag to refetch from source.
*/
requiresAllTracks?: boolean
forceRetrieveFromSource?: boolean
deleteExistingEntry?: boolean
}
Expand All @@ -246,29 +225,14 @@ export function* retrieveCollections(
const {
userId = null,
fetchTracks = false,
requiresAllTracks = false,
forceRetrieveFromSource = false,
deleteExistingEntry
} = config ?? {}
// @ts-ignore retrieve should be refactored to ts first
const { entries, uids } = yield* call(retrieve<Collection>, {
ids: collectionIds,
selectFromCache: function* (ids: ID[]) {
const res: {
[id: number]: Collection
} = yield* select(getCollections, { ids })
if (requiresAllTracks) {
const keys = Object.keys(res) as any
keys.forEach((collectionId: number) => {
const fullTrackCount = res[collectionId].track_count
const currentTrackCount = res[collectionId].tracks?.length ?? 0
if (currentTrackCount < fullTrackCount) {
// Remove the collection from the res so retrieve knows to get it from source
delete res[collectionId]
}
})
}
return res
return yield* select(getCollections, { ids })
},
getEntriesTimestamp: selectEntriesTimestamp,
retrieveFromSource: function* (ids: ID[]) {
Expand Down
2 changes: 0 additions & 2 deletions packages/web/src/common/store/pages/collection/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ function* watchFetchCollection() {
retrieveCollectionByPermalink,
permalink,
{
requiresAllTracks: true,
deleteExistingEntry: true,
forceRetrieveFromSource: forceFetch
}
)
} else {
retrievedCollections = yield call(retrieveCollections, [collectionId], {
requiresAllTracks: true,
deleteExistingEntry: true,
forceRetrieveFromSource: forceFetch
})
Expand Down

0 comments on commit e38ef5b

Please sign in to comment.