display logs with latest first

This commit is contained in:
Josh Harvey 2018-05-18 18:19:19 +03:00
parent be53de7326
commit 5d9533b7b4

View file

@ -4,7 +4,7 @@ const db = require('./db')
const pgp = require('pg-promise')()
const getMachineName = require('./machine-loader').getMachineName
const NUM_RESULTS = 1000
const NUM_RESULTS = 500
/**
* Get the latest log's timestamp
@ -62,7 +62,7 @@ function getUnlimitedMachineLogs (deviceId, until = new Date().toISOString()) {
where device_id=$1
and timestamp <= $2
and timestamp > ($2 - interval '2 days')
order by timestamp asc, serial asc`
order by timestamp desc, serial desc`
return Promise.all([db.any(sql, [ deviceId, until ]), getMachineName(deviceId)])
.then(([logs, machineName]) => ({
@ -75,7 +75,7 @@ function getMachineLogs (deviceId, until = new Date().toISOString()) {
const sql = `select id, log_level, timestamp, message from logs
where device_id=$1
and timestamp <= $3
order by timestamp asc, serial asc
order by timestamp desc, serial desc
limit $2`
return Promise.all([db.any(sql, [ deviceId, NUM_RESULTS, until ]), getMachineName(deviceId)])