Skip to content

Commit

Permalink
Optimise news management
Browse files Browse the repository at this point in the history
  • Loading branch information
slawkens committed Nov 18, 2024
1 parent 84d37c5 commit d0b4065
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions admin/pages/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

header('X-XSS-Protection:0');

// some constants, used mainly by database (cannot by modified without schema changes)
// some constants, used mainly by database (cannot be modified without schema changes)
const NEWS_TITLE_LIMIT = 100;
const NEWS_BODY_LIMIT = 65535; // maximum news body length
const ARTICLE_TEXT_LIMIT = 300;
Expand Down Expand Up @@ -136,9 +136,18 @@

$query = $db->query('SELECT * FROM ' . $db->tableName(TABLE_PREFIX . 'news'));
$newses = array();

$cachePlayers = [];
foreach ($query as $_news) {
$_player = new OTS_Player();
$_player->load($_news['player_id']);
$playerId = $_news['player_id'];
if (isset($cachePlayers[$playerId])) {
$_player = $cachePlayers[$playerId];
}
else {
$_player = new OTS_Player();
$_player->load($playerId);
$cachePlayers[$playerId] = $_player;
}

$newses[$_news['type']][] = array(
'id' => $_news['id'],
Expand All @@ -147,7 +156,7 @@
'title' => $_news['title'],
'date' => $_news['date'],
'player_name' => $_player->isLoaded() ? $_player->getName() : '',
'player_link' => $_player->isLoaded() ? getPlayerLink($_player->getName(), false) : '',
'player_link' => $_player->isLoaded() ? getPlayerLink($_player, false) : '',
);
}

Expand Down

0 comments on commit d0b4065

Please sign in to comment.