Adjust limits for performance

This commit is contained in:
Anthony Mineo 2020-04-14 18:22:26 -04:00
parent 56878c47d6
commit 2cf1a508d5
5 changed files with 18 additions and 18 deletions

View file

@ -6,20 +6,21 @@ class GameController {
// /games
async index({ inertia }) {
const pageTitle = "Last 1000 Games";
const gamesQry = await Database.table('games')
.distinct('game_id',
'map',
'gametype',
'stats',
'datestamp')
.where('game_id', '<>', 0)
.orderBy('game_id', 'desc')
.limit(1000)
const pageTitle = `Latest Games`;
const gamesQry = await Database.raw(`
SELECT distinct game_id,map,gametype, datestamp
FROM games
WHERE (stats->>'score' IS NOT NULL) AND (game_id <> 0)
ORDER BY game_id desc
LIMIT 2000;
`);
// filter out duplicate game_ids (https://dev.to/marinamosti/removing-duplicates-in-an-array-of-objects-in-js-with-sets-3fep)
const games = gamesQry.rows.reduce((game, current) => {
// filter out duplicate game_ids (https://dev.to/marinamosti/removing-duplicates-in-an-array-of-objects-in-js-with-sets-3fep)
const games = gamesQry.reduce((game, current) => {
const x = game.find(item => item.game_id === current.game_id);
if (!x) {
return game.concat([current]);

View file

@ -17,7 +17,7 @@ class PlayerController {
'updated_at')
.groupBy('player_guid')
.orderBy('player_name', 'asc')
.limit(2500)
.limit(1000)
return inertia.render('Players/Main', { pageTitle, players }, { edgeVar: 'server-variable' })
}
@ -32,6 +32,7 @@ class PlayerController {
'total_games_lakrabbitgame',
'total_games_sctfgame')
.where({ player_guid: request.params.player_guid })
.limit(50)
const playerStatData = await Database.from('games')
@ -39,6 +40,7 @@ class PlayerController {
'gametype',
'stats')
.where({ player_guid: request.params.player_guid })
.limit(50)
// Dynamically generate and sum the stats object

View file

@ -86,7 +86,7 @@ export class TwoLevelPieChart extends PureComponent {
const PlayerRow = (player, index) => {
// dont show scoreless players
if (Number(player.stats.score) <= 0){return}
//if (Number(player.stats.score) <= 0){return}
return <div className="flex flex-col rounded-lg shadow-lg overflow-hidden" key={index}>
<div className="bg-white shadow overflow-hidden sm:rounded-lg">

View file

@ -6,9 +6,6 @@ import Layout from '@/Shared/Layout'
const GameRow = (game, index) => {
// TODO: move this into controller for faster render
if (Number(game.stats.score) === 0){return}
return <li key={index}>
<InertiaLink href={`/game/${game.game_id}`} className="block hover:bg-gray-50 focus:outline-none focus:bg-gray-50 transition duration-150 ease-in-out">
<div className="flex items-center px-4 py-4 sm:px-6">

View file

@ -156,7 +156,7 @@ export default function Player(props) {
{ props.playerData.stats.map((player, index) => GameCard(player, index)) }
</div>
</div>
{/*
{/*
<div className="bg-white shadow overflow-hidden sm:rounded-md">
<div className="py-10 px-10"><code> {JSON.stringify(props.playerData.stats)}</code></div>