Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

[C-1624] Fix eager load #2352

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"idb-keyval": "3.2.0",
"inherits": "2.0.4",
"jimp": "0.6.8",
"js-sha3": "0.8.0",
"js-yaml": "3.13.1",
"jsmediatags": "3.8.1",
"lerp": "1.0.3",
Expand Down
8 changes: 4 additions & 4 deletions packages/web/src/common/store/account/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { identify } from 'common/store/analytics/actions'
import { retrieveCollections } from 'common/store/cache/collections/utils'
import { addPlaylistsNotInLibrary } from 'common/store/playlist-library/sagas'
import { updateProfileAsync } from 'common/store/profile/sagas'
import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForWrite, waitForRead } from 'utils/sagaHelpers'

import disconnectedWallets from './disconnected_wallet_fix.json'

Expand Down Expand Up @@ -283,7 +283,7 @@ export function* reCacheAccount() {

function* associateTwitterAccount(action) {
const { uuid, profile } = action.payload
yield waitForBackendAndAccount()
yield waitForWrite()
const audiusBackendInstance = yield getContext('audiusBackendInstance')
try {
const userId = yield select(getUserId)
Expand Down Expand Up @@ -337,15 +337,15 @@ function* associateInstagramAccount(action) {
}

function* fetchSavedAlbumsAsync() {
yield waitForBackendAndAccount()
yield waitForRead()
Copy link
Contributor

Choose a reason for hiding this comment

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

so much cleaner naming

const cachedSavedAlbums = yield select(getAccountAlbumIds)
if (cachedSavedAlbums.length > 0) {
yield call(retrieveCollections, null, cachedSavedAlbums)
}
}

function* fetchSavedPlaylistsAsync() {
yield waitForBackendAndAccount()
yield waitForRead()

// Fetch other people's playlists you've saved
yield fork(function* () {
Expand Down
7 changes: 7 additions & 0 deletions packages/web/src/common/store/backend/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export function* waitForBackendSetup() {
}
}

export function* waitForReachability() {
const isReachable = yield* select(getIsReachable)
if (!isReachable) {
yield* all([take(reachabilityActions.SET_REACHABLE)])
}
}

function* awaitReachability() {
const isNativeMobile = yield* getContext('isNativeMobile')
const isReachable = yield* select(getIsReachable)
Expand Down
18 changes: 9 additions & 9 deletions packages/web/src/common/store/cache/collections/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { fetchUsers } from 'common/store/cache/users/sagas'
import * as confirmerActions from 'common/store/confirmer/actions'
import { confirmTransaction } from 'common/store/confirmer/sagas'
import * as signOnActions from 'common/store/pages/signon/actions'
import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForWrite } from 'utils/sagaHelpers'

import { reformat } from './utils'
import {
Expand Down Expand Up @@ -64,7 +64,7 @@ function* watchCreatePlaylist() {
}

function* createPlaylistAsync(action) {
yield waitForBackendAndAccount()
yield waitForWrite()
// Potentially grab artwork from the initializing track.
if (action.initTrackId) {
const track = yield select(getTrack, { id: action.initTrackId })
Expand Down Expand Up @@ -288,7 +288,7 @@ function* watchEditPlaylist() {
}

function* editPlaylistAsync(action) {
yield waitForBackendAndAccount()
yield waitForWrite()
action.formFields.description = squashNewLines(action.formFields.description)

const userId = yield select(getUserId)
Expand Down Expand Up @@ -403,7 +403,7 @@ function* watchAddTrackToPlaylist() {
}

function* addTrackToPlaylistAsync(action) {
yield waitForBackendAndAccount()
yield waitForWrite()
const userId = yield select(getUserId)
if (!userId) {
yield put(signOnActions.openSignOn(false))
Expand Down Expand Up @@ -588,7 +588,7 @@ function* watchRemoveTrackFromPlaylist() {
}

function* removeTrackFromPlaylistAsync(action) {
yield waitForBackendAndAccount()
yield waitForWrite()
const userId = yield select(getUserId)
if (!userId) {
yield put(signOnActions.openSignOn(false))
Expand Down Expand Up @@ -650,7 +650,7 @@ function* removeTrackFromPlaylistAsync(action) {

// Removes the invalid track ids from the playlist by calling `dangerouslySetPlaylistOrder`
function* fixInvalidTracksInPlaylist(playlistId, userId, invalidTrackIds) {
yield waitForBackendAndAccount()
yield waitForWrite()
const audiusBackendInstance = yield getContext('audiusBackendInstance')
const apiClient = yield getContext('apiClient')
const removedTrackIds = new Set(invalidTrackIds)
Expand Down Expand Up @@ -794,7 +794,7 @@ function* watchOrderPlaylist() {
}

function* orderPlaylistAsync(action) {
yield waitForBackendAndAccount()
yield waitForWrite()
const userId = yield select(getUserId)
if (!userId) {
yield put(signOnActions.openSignOn(false))
Expand Down Expand Up @@ -933,7 +933,7 @@ function* watchPublishPlaylist() {
}

function* publishPlaylistAsync(action) {
yield waitForBackendAndAccount()
yield waitForWrite()
const userId = yield select(getUserId)
if (!userId) {
yield put(signOnActions.openSignOn(false))
Expand Down Expand Up @@ -1023,7 +1023,7 @@ function* watchDeletePlaylist() {
}

function* deletePlaylistAsync(action) {
yield waitForBackendAndAccount()
yield waitForWrite()
const userId = yield select(getUserId)
if (!userId) {
yield put(signOnActions.openSignOn(false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { uniqBy } from 'lodash'
import { put, select } from 'typed-redux-saga'

import { reformat as reformatUser } from 'common/store/cache/users/utils'
import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForRead } from 'utils/sagaHelpers'

const getAccountUser = accountSelectors.getAccountUser

Expand All @@ -22,7 +22,7 @@ const getAccountUser = accountSelectors.getAccountUser
export function* addUsersFromCollections(
metadataArray: Array<UserCollectionMetadata>
) {
yield* waitForBackendAndAccount()
yield* waitForRead()
const audiusBackendInstance = yield* getContext('audiusBackendInstance')
const accountUser = yield* select(getAccountUser)
const currentUserId = accountUser?.user_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { call, select } from 'typed-redux-saga'

import { retrieve } from 'common/store/cache/sagas'
import { retrieveTracks } from 'common/store/cache/tracks/utils'
import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForRead } from 'utils/sagaHelpers'

import { addTracksFromCollections } from './addTracksFromCollections'
import { addUsersFromCollections } from './addUsersFromCollections'
Expand Down Expand Up @@ -89,7 +89,7 @@ export function* retrieveTracksForCollections(
* Retrieves a single collection via API client
*/
export function* retrieveCollection(playlistId: ID) {
yield* waitForBackendAndAccount()
yield* waitForRead()
const apiClient = yield* getContext('apiClient')
const userId = yield* select(getUserId)
const playlists = yield* call([apiClient, 'getPlaylist'], {
Expand Down
8 changes: 4 additions & 4 deletions packages/web/src/common/store/cache/tracks/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { confirmTransaction } from 'common/store/confirmer/sagas'
import * as signOnActions from 'common/store/pages/signon/actions'
import { updateProfileAsync } from 'common/store/profile/sagas'
import { dominantColor } from 'utils/imageProcessingUtil'
import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForWrite } from 'utils/sagaHelpers'

const { getUser } = cacheUsersSelectors
const { getTrack } = cacheTracksSelectors
Expand Down Expand Up @@ -170,7 +170,7 @@ function* confirmEditTrack(
isNowListed,
currentTrack
) {
yield waitForBackendAndAccount()
yield waitForWrite()
const audiusBackendInstance = yield getContext('audiusBackendInstance')
const apiClient = yield getContext('apiClient')
yield put(
Expand Down Expand Up @@ -257,7 +257,7 @@ function* watchEditTrack() {

function* deleteTrackAsync(action) {
const audiusBackendInstance = yield getContext('audiusBackendInstance')
yield waitForBackendAndAccount()
yield waitForWrite()
const userId = yield select(getUserId)
if (!userId) {
yield put(signOnActions.openSignOn(false))
Expand Down Expand Up @@ -302,7 +302,7 @@ function* deleteTrackAsync(action) {
}

function* confirmDeleteTrack(trackId) {
yield waitForBackendAndAccount()
yield waitForWrite()
const audiusBackendInstance = yield getContext('audiusBackendInstance')
const apiClient = yield getContext('apiClient')
yield put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@audius/common'
import { select, call, put } from 'typed-redux-saga'

import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForRead } from 'utils/sagaHelpers'

import { processAndCacheTracks } from './processAndCacheTracks'
const { getTrack } = cacheTracksSelectors
Expand All @@ -27,7 +27,7 @@ const INITIAL_FETCH_LIMIT = 6
* @param trackId the parent track for which to fetch remixes
*/
export function* fetchAndProcessRemixes(trackId: ID) {
yield* waitForBackendAndAccount()
yield* waitForRead()
const apiClient = yield* getContext('apiClient')
const currentUserId = yield* select(getUserId)
const {
Expand Down Expand Up @@ -80,7 +80,7 @@ export function* fetchAndProcessRemixes(trackId: ID) {
* @param trackId the track for which to fetch remix parents
*/
export function* fetchAndProcessRemixParents(trackId: ID) {
yield* waitForBackendAndAccount()
yield* waitForRead()
const apiClient = yield* getContext('apiClient')
const currentUserId = yield* select(getUserId)
const remixParents = (yield* call([apiClient, 'getRemixing'], {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@audius/common'
import { call, put } from 'redux-saga/effects'

import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForRead } from 'utils/sagaHelpers'

import { processAndCacheTracks } from './processAndCacheTracks'
const { getTrack } = cacheTracksSelectors
Expand All @@ -24,7 +24,7 @@ const { getTrack } = cacheTracksSelectors
* @param trackId the parent track for which to fetch stems
*/
export function* fetchAndProcessStems(trackId: ID) {
yield* waitForBackendAndAccount()
yield* waitForRead()
const apiClient = yield* getContext('apiClient')

const stems: StemTrackMetadata[] = yield call(
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/common/store/cache/tracks/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { uniqBy } from 'lodash'
import { put, select } from 'typed-redux-saga'

import { reformat as reformatUser } from 'common/store/cache/users/utils'
import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForRead } from 'utils/sagaHelpers'
const getAccountUser = accountSelectors.getAccountUser

/**
Expand All @@ -22,7 +22,7 @@ const getAccountUser = accountSelectors.getAccountUser
export function* addUsersFromTracks<T extends TrackMetadata & { user?: User }>(
metadataArray: T[]
) {
yield* waitForBackendAndAccount()
yield* waitForRead()
const audiusBackendInstance = yield* getContext('audiusBackendInstance')
const accountUser = yield* select(getAccountUser)
const currentUserId = accountUser?.user_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@audius/common'
import { put, call } from 'typed-redux-saga'

import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForRead } from 'utils/sagaHelpers'

import { addUsersFromTracks } from './helpers'
import { reformat } from './reformat'
Expand All @@ -20,7 +20,7 @@ import { reformat } from './reformat'
export function* processAndCacheTracks<T extends TrackMetadata>(
tracks: T[]
): Generator<any, Track[], any> {
yield* waitForBackendAndAccount()
yield* waitForRead()
const audiusBackendInstance = yield* getContext('audiusBackendInstance')
// Add users
yield* call(addUsersFromTracks, tracks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { call, put, select, spawn } from 'typed-redux-saga'

import { retrieve } from 'common/store/cache/sagas'
import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForRead } from 'utils/sagaHelpers'

import {
fetchAndProcessRemixes,
Expand Down Expand Up @@ -65,7 +65,7 @@ export function* retrieveTrackByHandleAndSlug({
return track
},
retrieveFromSource: function* (permalinks: string[]) {
yield* waitForBackendAndAccount()
yield* waitForRead()
const apiClient = yield* getContext('apiClient')
const userId = yield* select(getUserId)
const track = yield* call((args) => {
Expand Down Expand Up @@ -153,7 +153,7 @@ export function* retrieveTracks({
withRemixes = false,
withRemixParents = false
}: RetrieveTracksArgs) {
yield* waitForBackendAndAccount()
yield* waitForRead()
const currentUserId = yield* select(getUserId)

// In the case of unlisted tracks, trackIds contains metadata used to fetch tracks
Expand Down Expand Up @@ -217,7 +217,7 @@ export function* retrieveTracks({
return selected
},
retrieveFromSource: function* (ids: ID[] | UnlistedTrackRequest[]) {
yield* waitForBackendAndAccount()
yield* waitForRead()
const apiClient = yield* getContext('apiClient')
let fetched: UserTrackMetadata | UserTrackMetadata[] | null | undefined
if (canBeUnlisted) {
Expand Down
6 changes: 3 additions & 3 deletions packages/web/src/common/store/cache/users/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
getStatus
} from 'common/store/service-selection/selectors'
import { fetchServicesFailed } from 'common/store/service-selection/slice'
import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForWrite, waitForRead } from 'utils/sagaHelpers'

import { pruneBlobValues, reformat } from './utils'
const { removePlaylistLibraryTempPlaylists } = playlistLibraryHelpers
Expand All @@ -42,7 +42,7 @@ const { getAccountUser, getUserId } = accountSelectors
* If the user is not a creator, upgrade the user to a creator node.
*/
export function* upgradeToCreator() {
yield waitForBackendAndAccount()
yield waitForWrite()
const audiusBackendInstance = yield getContext('audiusBackendInstance')
const user = yield select(getAccountUser)

Expand Down Expand Up @@ -118,7 +118,7 @@ export function* fetchUsers(
}

function* retrieveUserByHandle(handle, retry) {
yield waitForBackendAndAccount()
yield waitForRead()
const apiClient = yield getContext('apiClient')
const userId = yield select(getUserId)
if (Array.isArray(handle)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { User, Kind, makeUid, getContext, cacheActions } from '@audius/common'
import { put } from 'typed-redux-saga'

import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForRead } from 'utils/sagaHelpers'

import { reformat } from './reformat'

export function* processAndCacheUsers(users: User[]) {
yield* waitForBackendAndAccount()
yield* waitForRead()
const audiusBackendInstance = yield* getContext('audiusBackendInstance')
const reformattedUser = users.map((user) => {
return reformat(user, audiusBackendInstance)
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/common/store/notifications/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
subscribeToUserAsync,
unsubscribeFromUserAsync
} from 'common/store/social/users/sagas'
import { waitForBackendAndAccount } from 'utils/sagaHelpers'
import { waitForRead } from 'utils/sagaHelpers'

import { watchNotificationError } from './errorSagas'
const { fetchReactionValues } = reactionsUIActions
Expand Down Expand Up @@ -195,7 +195,7 @@ export function* fetchNotifications(action: FetchNotifications) {
export function* parseAndProcessNotifications(
notifications: Notification[]
): Generator<any, Notification[], any> {
yield* waitForBackendAndAccount()
yield* waitForRead()
/**
* Parse through the notifications & collect user /track / collection IDs
* that the notification references to fetch
Expand Down
Loading