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 // /games
async index({ inertia }) { async index({ inertia }) {
const pageTitle = "Last 1000 Games";
const gamesQry = await Database.table('games') const pageTitle = `Latest Games`;
.distinct('game_id',
'map', const gamesQry = await Database.raw(`
'gametype', SELECT distinct game_id,map,gametype, datestamp
'stats', FROM games
'datestamp') WHERE (stats->>'score' IS NOT NULL) AND (game_id <> 0)
.where('game_id', '<>', 0) ORDER BY game_id desc
.orderBy('game_id', 'desc') LIMIT 2000;
.limit(1000) `);
// 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); const x = game.find(item => item.game_id === current.game_id);
if (!x) { if (!x) {
return game.concat([current]); return game.concat([current]);

View file

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

View file

@ -86,7 +86,7 @@ export class TwoLevelPieChart extends PureComponent {
const PlayerRow = (player, index) => { const PlayerRow = (player, index) => {
// dont show scoreless players // 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}> return <div className="flex flex-col rounded-lg shadow-lg overflow-hidden" key={index}>
<div className="bg-white shadow overflow-hidden sm:rounded-lg"> <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) => { const GameRow = (game, index) => {
// TODO: move this into controller for faster render
if (Number(game.stats.score) === 0){return}
return <li key={index}> 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"> <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"> <div className="flex items-center px-4 py-4 sm:px-6">