Skip to content

Commit

Permalink
Attempt to reduce unneeded SQL logging on yahrzeit download
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Sep 29, 2024
1 parent 00d1d19 commit 421c552
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ export function makeLogger(logDir) {
* @return {Object}
*/
export function makeLogInfo(ctx) {
const status = ctx.response.status;
const info = {
status: ctx.response.status,
status: status,
length: ctx.response.length,
duration: Date.now() - ctx.state.startTime,
ip: getIpAddress(ctx),
Expand Down Expand Up @@ -104,7 +105,7 @@ export function makeLogInfo(ctx) {
}
}
}
if (ctx.state.mysqlQuery) {
if (ctx.state.mysqlQuery && status !== 200) {
info.sql = ctx.state.mysqlQuery;
}
return info;
Expand Down
16 changes: 10 additions & 6 deletions src/yahrzeitCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ export async function getYahrzeitDetailsFromDb(ctx, id) {
const obj = row.contents;
if (!row.downloaded) {
const sqlUpdate = 'UPDATE yahrzeit SET downloaded = 1, updated = NOW() WHERE id = ?';
db.execute2(ctx, {sql: sqlUpdate, values: [id], timeout: 1000}).catch((err) => {
ctx.logger.error(err);
});
db.execute2(ctx, {sql: sqlUpdate, values: [id], timeout: 1000})
.then(() => {})
.catch((err) => {
ctx.logger.error(err);
});
}
const sql2 = 'REPLACE INTO yahrzeit_atime (id, ts) VALUES (?, NOW())';
db.execute2(ctx, {sql: sql2, values: [id], timeout: 1000}).catch((err) => {
ctx.logger.error(err);
});
db.execute2(ctx, {sql: sql2, values: [id], timeout: 1000})
.then(() => {})
.catch((err) => {
ctx.logger.error(err);
});
// convert from 'x' fields back into ymd fields
const maxId = getMaxYahrzeitId(obj);
for (let i = 1; i <= maxId; i++) {
Expand Down

0 comments on commit 421c552

Please sign in to comment.