* Improved message trimming
* Better logs, code cleanup, etc. around trimming
This commit is contained in:
parent
e19b725aa8
commit
b8a23b827c
|
@ -370,18 +370,18 @@ function getMessageListForArea(options, areaTag, cb) {
|
||||||
]
|
]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var msgList = [];
|
let msgList = [];
|
||||||
|
|
||||||
async.series(
|
async.series(
|
||||||
[
|
[
|
||||||
function fetchMessages(callback) {
|
function fetchMessages(callback) {
|
||||||
msgDb.each(
|
msgDb.each(
|
||||||
'SELECT message_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, modified_timestamp, view_count ' +
|
`SELECT message_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, modified_timestamp, view_count
|
||||||
'FROM message ' +
|
FROM message
|
||||||
'WHERE area_tag = ? ' +
|
WHERE area_tag = ?
|
||||||
'ORDER BY message_id;',
|
ORDER BY message_id;`,
|
||||||
[ areaTag.toLowerCase() ],
|
[ areaTag.toLowerCase() ],
|
||||||
function msgRow(err, row) {
|
(err, row) => {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
msgList.push(getMessageFromRow(row));
|
msgList.push(getMessageFromRow(row));
|
||||||
}
|
}
|
||||||
|
@ -477,20 +477,17 @@ function trimMessageAreasScheduledEvent(args, cb) {
|
||||||
|
|
||||||
msgDb.run(
|
msgDb.run(
|
||||||
`DELETE FROM message
|
`DELETE FROM message
|
||||||
WHERE message_id IN
|
WHERE message_id IN(
|
||||||
(SELECT message_id
|
SELECT message_id
|
||||||
FROM message
|
FROM message
|
||||||
WHERE area_tag = ?
|
WHERE area_tag = ?
|
||||||
ORDER BY message_id
|
ORDER BY message_id DESC
|
||||||
LIMIT (MAX(0, (SELECT COUNT()
|
LIMIT -1 OFFSET ${areaInfo.maxMessages}
|
||||||
FROM message
|
|
||||||
WHERE area_tag = ?) - ${areaInfo.maxMessages}
|
|
||||||
))
|
|
||||||
);`,
|
);`,
|
||||||
[ areaInfo.areaTag, areaInfo.areaTag],
|
[ areaInfo.areaTag],
|
||||||
err => {
|
err => {
|
||||||
if(err) {
|
if(err) {
|
||||||
Log.warn( { areaInfo : areaInfo, error : err.toString(), type : 'maxMessages' }, 'Error trimming message area');
|
Log.error( { areaInfo : areaInfo, err : err, type : 'maxMessages' }, 'Error trimming message area');
|
||||||
} else {
|
} else {
|
||||||
Log.debug( { areaInfo : areaInfo, type : 'maxMessages' }, 'Area trimmed successfully');
|
Log.debug( { areaInfo : areaInfo, type : 'maxMessages' }, 'Area trimmed successfully');
|
||||||
}
|
}
|
||||||
|
@ -510,7 +507,7 @@ function trimMessageAreasScheduledEvent(args, cb) {
|
||||||
[ areaInfo.areaTag ],
|
[ areaInfo.areaTag ],
|
||||||
err => {
|
err => {
|
||||||
if(err) {
|
if(err) {
|
||||||
Log.warn( { areaInfo : areaInfo, error : err.toString(), type : 'maxAgeDays' }, 'Error trimming message area');
|
Log.warn( { areaInfo : areaInfo, err : err, type : 'maxAgeDays' }, 'Error trimming message area');
|
||||||
} else {
|
} else {
|
||||||
Log.debug( { areaInfo : areaInfo, type : 'maxAgeDays' }, 'Area trimmed successfully');
|
Log.debug( { areaInfo : areaInfo, type : 'maxAgeDays' }, 'Area trimmed successfully');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue