GameQ icon indicating copy to clipboard operation
GameQ copied to clipboard

Add option to only return `normalized` data.

Open ZacharyDuBois opened this issue 7 years ago • 4 comments

Add an option to only return normalized data (data prefixed with gq_). Right now, a bunch of useless server information is returned when not requested. Adding some sort of option to only get X,Y,Z values would be nice. It would also prevent wasted memory (assuming this is implemented corrected) when querying servers that return more than necessary data like TeamSpeak or servers that don't return valid data.

ZacharyDuBois avatar May 01 '17 06:05 ZacharyDuBois

For those who need this sort of functionality now, heres a quick array_filter() you can run.

$GameQ = new \GameQ\GameQ();
$GameQ->addServers($servers);
$GameQ->addFilter('normalise');

$results = $GameQ->process();

foreach ($results as $id => $result) {
    $result = array_filter($result, function ($key) {
        return (preg_match('/gq\_.+/', $key) === 1);
    }, ARRAY_FILTER_USE_KEY);

    $results[$id] = $result;
}

ZacharyDuBois avatar May 01 '17 06:05 ZacharyDuBois

It would be possible to add a filter to only return the gq_ data. Using a filter will actually make things slightly slower because it is another process to jump through to filter out all of the non gq_ prefixed data.

All of the data is returned when process() is invoked because there is no way to tell the server when querying it I only want these specific data points and ignore the rest. Depending on the server response format the specific data point you want may be near the end of the data stream and the only way to get to it is to parse everything before it. There is no way to jump forward that would provide any speed increase. Not adding items to the response array would save some memory but since it is all text it wouldn't be significant unless you are running 100's of servers at a time.

Austinb avatar Jun 27 '17 14:06 Austinb

Correct but this also would help prevent the issue I had in #378. Depending how each game's query works, you could theoretically for a lot of games request just specific data. Such as TS3, you can just request online users instead of requesting the entire channel tree, etc.

ZacharyDuBois avatar Jun 29 '17 03:06 ZacharyDuBois

Stale issue message

github-actions[bot] avatar Dec 09 '19 00:12 github-actions[bot]