chesslablab / chess-api

REST-like chess API.
https://chesslablab.github.io/chess-api/
MIT License
23 stars 10 forks source link

Reimplement the GET /v1/autocomplete/player endpoint #154

Closed programarivm closed 7 months ago

programarivm commented 7 months ago

The GET /v1/autocomplete/player endpoint has demonstrated to be not effective for autocompleting players names while users are entering input in the Search Games dialog. See https://github.com/chesslablab/website/issues/111

This is mainly due to the fact that all players names are currently being downloaded first in the form of an array for the browser to then perform search queries on that huge array.

figure_02

Figure 1. Click on Search Games and enter some text in the White or in the Black text fields.

Attached below is the current code for the GET /v1/autocomplete/player endpoint.

<?php

namespace ChessApi\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class AutocompletePlayerController extends AbstractController
{
    const DATA_FOLDER = __DIR__.'/../../data/autocomplete';

    const AUTOCOMPLETE_PLAYER_FILE = 'players.json';

    public function index(Request $request): Response
    {
        $content = file_get_contents(self::DATA_FOLDER.'/'.self::AUTOCOMPLETE_PLAYER_FILE);

        $response = new Response();
        $response->setContent($content);
        $response->headers->set('Content-Type', 'application/json');

        return $response;
    }
}

This endpoint needs to be reimplemented as a POST request in order to perform a database search based on the incoming input value rather than downloading the players.json file.

Happy coding!