Skip to content
Open
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
48 changes: 26 additions & 22 deletions src/actions/receive-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1416,9 +1416,9 @@ export function retrieveProfilesToCompare(
dispatch(waitingForProfileFromUrl());

try {
// First we get a state from each URL. From these states we'll get all the
// data we need to fetch and process the profiles.
const profileStates = await Promise.all(
// Fetch each profile first so we can pass the upgrade info to
// stateFromLocation, allowing URL upgraders to work correctly.
const profilesAndStates = await Promise.all(
profileViewUrls.map(async (url) => {
if (
url.startsWith('https://perfht.ml/') ||
Expand All @@ -1427,28 +1427,23 @@ export function retrieveProfilesToCompare(
) {
url = await expandUrl(url);
}
// TODO: Pass the profileUpgradeInfo here. See #5871.
return stateFromLocation(new URL(url));
})
);

// Then we retrieve the profiles from the online store, and unserialize
// and process them if needed.
const promises = profileStates.map(
async ({ dataSource, hash, profileUrl }) => {
const preliminaryState = stateFromLocation(new URL(url));
let { profileUrl } = preliminaryState;
const { dataSource, hash } = preliminaryState;

switch (dataSource) {
case 'public':
// Use a URL from the public store.
profileUrl = getProfileUrlForHash(hash);
break;
case 'from-url':
// Use the profile URL in the decoded state, decoded from the input URL.
break;
default:
throw new Error(
'Only public uploaded profiles are supported by the comparison function.'
);
}

const response: ProfileOrZip = await _fetchProfile({
url: profileUrl,
onTemporaryError: (e: TemporaryError) => {
Expand All @@ -1458,18 +1453,27 @@ export function retrieveProfilesToCompare(
if (response.responseType !== 'PROFILE') {
throw new Error('Expected to receive a profile from _fetchProfile');
}
const serializedProfile = response.profile;

const profile =
unserializeProfileOfArbitraryFormat(serializedProfile);
return profile;
}
const upgradeInfo: ProfileUpgradeInfo = {};
const profile = await unserializeProfileOfArbitraryFormat(
response.profile,
profileUrl,
upgradeInfo
);

const profileState = stateFromLocation(new URL(url), {
profile,
upgradeInfo,
});

return { profile, profileState };
})
);

// Once all profiles have been fetched and unserialized, we can start
// pushing them to a brand new profile. This resulting profile will keep
// only the 2 selected threads from the 2 profiles.
const profiles = await Promise.all(promises);
const profiles = profilesAndStates.map(({ profile }) => profile);
const profileStates = profilesAndStates.map(
({ profileState }) => profileState
);

const {
profile: resultProfile,
Expand Down