Skip to content

Commit

Permalink
Update changed api to be more performant
Browse files Browse the repository at this point in the history
  • Loading branch information
leotsarev committed Dec 4, 2023
1 parent 09975e5 commit 032ebda
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
22 changes: 14 additions & 8 deletions public_html/appcode/api.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
<?php
function strip_game_object_before_json($result)
function strip_game_object_before_json($result, $whitelisted_fields = null)
{
if ($result['show_flags'])
if (!$whitelisted_fields)
{
$whitelisted_fields =
array ("id", "name", "uri", "begin", "time", "type", "polygon", "mg", "email", "status", "comment", "region", "sub_region_id", "deleted_flag",
"players_count", "allrpg_info_id", "polygon_name", "game_type_name", "sub_region_disp_name", "sub_region_name", "status_name", 'vk_club', 'lj_comm', 'fb_comm'
, 'update_date'
);
}
if (array_key_exists('show_flags', $result) && $result['show_flags'])
{
return array(
'id' => $result['id'],
'access-denied' => 1,
);
}
if ($result['redirect_id'])
if (array_key_exists('redirect_id', $result) && $result['redirect_id'])
{
return array(
'id' => $result['id'],
'redirect_id' => $result['redirect_id'],
);
}
if ($result['hide_email'])
if (array_key_exists('hide_email', $result) && $result['hide_email'])
{
unset($result['email']);
}
$enabled_fields =
array ("id", "name", "uri", "begin", "time", "type", "polygon", "mg", "email", "status", "comment", "region", "sub_region_id", "deleted_flag",
"players_count", "allrpg_info_id", "polygon_name", "game_type_name", "sub_region_disp_name", "sub_region_name", "status_name", 'vk_club', 'lj_comm', 'fb_comm');

$response = array();
foreach ($result as $key => $value)
{
if (array_search($key, $enabled_fields) === FALSE)
if (array_search($key, $whitelisted_fields) === FALSE)
{
continue;
}
Expand Down
13 changes: 12 additions & 1 deletion public_html/appcode/logic/gamelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,18 @@ function get_future_games()
function get_games_by_timestamp($timestamp)
{
$timestamp = intval ($timestamp);
return _get_games("\"update_date\" > to_timestamp($timestamp) AND kgd.\"order\"=0 AND kg.deleted_flag =0", "INNER JOIN \"ki_updates\" ki ON kg.id = ki.game_id", "update_date DESC");
$sql = connect();
$query = "SELECT
kg.id, kg.redirect_id,
MAX(update_date) AS update_date
FROM ki_games kg
INNER JOIN ki_updates ki ON kg.id = ki.game_id
WHERE update_date > to_timestamp($timestamp)
GROUP BY kg.id
ORDER BY update_date DESC
";
return $sql -> Query ($query);
}

?>

0 comments on commit 032ebda

Please sign in to comment.