Skip to content

Commit

Permalink
refactor: Only load the last few pages of the character history.
Browse files Browse the repository at this point in the history
It's stupid to load all history at all times, when you can just grab the pages you need.
  • Loading branch information
itssimple committed May 26, 2022
1 parent 0cc2e21 commit 253130f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/scripts/destiny2/apiClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,15 @@ export class DestinyApiClient {

return new Promise<void>(async (resolve, reject) => {
let savedAmount = maxActivitiesPerFetch;
let page = 0;
let localCharacterHistory = await db.getStorageItems(
"playerActivity",
(item) => item.value.characterId == characterId
);
let page = Math.floor(localCharacterHistory.length / 250);
log(
"CHARACTER-HISTORY",
`Loaded local character history, found ${localCharacterHistory.length} items, skipping to page ${page}`
);

while (savedAmount > 0) {
let historyActivityUrl = `https://www.bungie.net/Platform/Destiny2/-1/Account/${membershipId}/Character/${characterId}/Stats/Activities?count=${maxActivitiesPerFetch}&page=${page}`;
Expand Down

0 comments on commit 253130f

Please sign in to comment.