Skip to content
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
18 changes: 16 additions & 2 deletions packages/web/src/common/store/pages/signon/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ function* getArtistsToFollow() {
yield put(signOnActions.setUsersToFollow(users))
}

function* fetchDefaultFollowArtists() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice, so the ideas is that these are in the cache now, so when user follows them, they will be updated appropriately?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes! basically just trying to fetch the users in parallel early in the flow to speed up the follow process during sign up (and thus maximizes the chance that the follows will be complete once the users hit the feed)

yield call(waitForRead)
try {
const defaultFollowUserIds = yield call(getDefautFollowUserIds)
yield call(fetchUsers, Array.from(defaultFollowUserIds))
} catch (e) {
console.error('Unable to fetch default follow artists', e)
}
}

function* fetchAllFollowArtist() {
yield call(waitForRead)
try {
Expand Down Expand Up @@ -495,10 +505,10 @@ function* signUp() {
}
},
function* () {
yield put(signOnActions.signUpSucceeded())
yield put(signOnActions.sendWelcomeEmail(name))
yield call(fetchAccountAsync, { isSignUp: true })
yield put(signOnActions.followArtists())
yield put(signOnActions.signUpSucceeded())
},
function* ({ timeout }) {
if (timeout) {
Expand Down Expand Up @@ -728,7 +738,11 @@ function* watchValidateHandle() {
}

function* watchSignUp() {
yield takeLatest(signOnActions.SIGN_UP, signUp)
yield takeLatest(signOnActions.SIGN_UP, function* (action) {
// Fetch the default follow artists in parallel so that we don't have to block on this later (thus adding perceived sign up time) in the follow artists step.
yield fork(fetchDefaultFollowArtists)
yield signUp(action)
})
}

function* watchSignIn() {
Expand Down
14 changes: 12 additions & 2 deletions packages/web/src/common/store/social/users/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { call, select, takeEvery, put } from 'typed-redux-saga'

import { make } from 'common/store/analytics/actions'
import { adjustUserField } from 'common/store/cache/users/sagas'
import { adjustUserField, fetchUsers } from 'common/store/cache/users/sagas'
import * as signOnActions from 'common/store/pages/signon/actions'
import { profilePage } from 'utils/route'
import { waitForWrite } from 'utils/sagaHelpers'
Expand Down Expand Up @@ -48,9 +48,19 @@ export function* followUser(
}

const users = yield* select(getUsers, { ids: [action.userId, accountId] })
const followedUser = users[action.userId]
let followedUser = users[action.userId]
const currentUser = users[accountId]

if (!followedUser) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need this check if we are assuming the forked fetchDefaultUsers will run beforehand?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

technically no, but this is more to future proof this kind of thing in the future for different flows

try {
// If we haven't cached the followed user, need to fetch and cache it first to ensure that we have the correct `does_current_user_follow` on the user value before the follow gets indexed.
const { entries } = yield* call(fetchUsers, [action.userId])
followedUser = entries[action.userId]
} catch (e) {
console.error('Failed to fetch the followed user', action.userId)
}
}

if (followedUser) {
// Increment the followed user's follower count
yield* put(
Expand Down