Skip to content

Commit

Permalink
perf(user): hide completion progress behind authentication (#1812)
Browse files Browse the repository at this point in the history
  • Loading branch information
wescopeland authored Sep 1, 2023
1 parent 6baf300 commit 9128fc7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/Helpers/database/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function getUserActivityRange(string $user, ?string &$firstLogin, ?string &$last
return false;
}

function getUserPageInfo(string $user, int $numGames = 0, int $numRecentAchievements = 0): array
function getUserPageInfo(string $user, int $numGames = 0, int $numRecentAchievements = 0, bool $isAuthenticated = false): array
{
if (!getAccountDetails($user, $userInfo)) {
return [];
Expand All @@ -186,7 +186,8 @@ function getUserPageInfo(string $user, int $numGames = 0, int $numRecentAchievem

$libraryOut['Rank'] = getUserRank($user);

$libraryOut['RecentlyPlayedCount'] = getRecentlyPlayedGames($user, 0, $numGames, $recentlyPlayedData);
$recentlyPlayedData = [];
$libraryOut['RecentlyPlayedCount'] = $isAuthenticated ? getRecentlyPlayedGames($user, 0, $numGames, $recentlyPlayedData) : 0;
$libraryOut['RecentlyPlayed'] = $recentlyPlayedData;

if ($libraryOut['RecentlyPlayedCount'] > 0) {
Expand Down
2 changes: 1 addition & 1 deletion public/API/API_GetUserSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
$recentGamesPlayed = (int) request()->query('g', '5');
$recentAchievementsEarned = (int) request()->query('a', '10');

$retVal = getUserPageInfo($user, $recentGamesPlayed, $recentAchievementsEarned);
$retVal = getUserPageInfo($user, $recentGamesPlayed, $recentAchievementsEarned, true);

if (empty($retVal)) {
return response()->json([
Expand Down
9 changes: 6 additions & 3 deletions public/userInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

$maxNumGamesToFetch = requestInputSanitized('g', 5, 'integer');

$userMassData = getUserPageInfo($userPage, numGames: $maxNumGamesToFetch);
$userMassData = getUserPageInfo($userPage, numGames: $maxNumGamesToFetch, isAuthenticated: $user !== null);
if (empty($userMassData)) {
abort(404);
}
Expand Down Expand Up @@ -52,7 +52,7 @@
$totalSoftcoreAchievements = 0;

// Get user's list of played games and pct completion
$userCompletedGamesList = getUsersCompletedGamesAndMax($userPage);
$userCompletedGamesList = $user ? getUsersCompletedGamesAndMax($userPage) : [];

$excludedConsoles = ["Hubs", "Events"];

Expand Down Expand Up @@ -630,7 +630,10 @@ function resize() {
$prefersHiddenUserCompletedSets = request()->cookie('prefers_hidden_user_completed_sets') === 'true';

RenderSiteAwards(getUsersSiteAwards($userPage), $userPage);
RenderCompletedGamesList($userCompletedGamesList, $userPage, $prefersHiddenUserCompletedSets);

if (count($userCompletedGamesList) >= 1) {
RenderCompletedGamesList($userCompletedGamesList, $userPage, $prefersHiddenUserCompletedSets);
}

echo "<div id='achdistribution' class='component'>";
echo "<h3>Recent Progress</h3>";
Expand Down

0 comments on commit 9128fc7

Please sign in to comment.