Skip to content

Conversation

@WedgeSparda
Copy link

@WedgeSparda WedgeSparda commented Jul 24, 2024

Hi, in order to support pagination in any API client, I added a couple of params offset and count.

These are the same parameter used by getGamesListByDev function, but the API endpoint wasn't support them.

I added a test for these new parameters but despite working in reality, test is rising an error related to SQL_CALC_FOUND_ROWS not being supported.

API Docs PR is here

@WedgeSparda WedgeSparda changed the title [API] Added offset and count parameters to GetGameList feat(api): Added offset and count parameters to GetGameList Jul 24, 2024
@wescopeland
Copy link
Member

Overall I agree with this change. This is one of the few endpoints that at some point we should seriously consider introducing a breaking change into that forces users to paginate it.

@WedgeSparda
Copy link
Author

WedgeSparda commented Jul 25, 2024

@wescopeland I'm playing with Eloquent and I got this code, instead of using getGamesListByDev

$query = DB::table('GameData')
    ->where('ConsoleID', $consoleID);

if ($withAchievements) {
    $query->whereExists(function ($query) {
        $query
            ->from('Achievements')
            ->whereColumn('GameData.ID', 'Achievements.GameID');
    });
}

if ($offset > 0 && $count > 0) {
    $query
        ->offset($offset)
        ->limit($count);
}

$response = $query->get();

In order to check if the game has Achievements, I'm using the foreign key from Achievements table since I'm not sure if achievements_published field is reliable. In the development set of data that field is NULL for all games.

@wescopeland
Copy link
Member

It's safe to assume achievements_published is reliable. I'll add something to my TODO list to ensure the seeder is spitting out sane data for that field.

@WedgeSparda
Copy link
Author

@wescopeland So I took your advice and completely replaced the use of getGamesListByDev with Eloquent. Now the tests are passing correctly and the new params work as expected (I added a new test step to be sure about it).

Hope you like my code 😅

@WedgeSparda
Copy link
Author

@wescopeland

All problems raised have beed fixed. Also added a new test when only count param is present.

@wescopeland wescopeland changed the title feat(api): Added offset and count parameters to GetGameList feat(api): add offset and count parameters to API_GetGameList Aug 4, 2024
@wescopeland wescopeland merged commit 0f00853 into RetroAchievements:master Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants