Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions server/augmented/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@

// [potential-nodebb-core]
Messages.count = function (callback) {
db.keys('message:*', (err, keys) => {
// Use the Data helper instead of direct db.keys call
Data.count('messages:mid', (err, count) => {
if (err) {
callback(err);
return callback(err);
}
callback(err, keys.length);
callback(null, count);
});
};

Expand All @@ -139,20 +140,15 @@
}
options = options || {};

const prefix = 'message:';
db.keys(`${prefix}*`, (err, keys) => {
if (err) {
return callback(err);
// Use Data.each instead of direct db.keys call
return Data.each('messages:mid', 'message:', (message, next) => {
if (message) {
// The message object should already have the mid from Data.each
iterator(message, next);
} else {
next();
}
async.mapLimit(keys, options.batch || 100, (key, next) => {
db.getObject(key, (err, message) => {
if (message) {
message.mid = key.replace(prefix, '');
}
iterator(message, next);
});
}, callback);
});
}, options, callback);
};

module.exports = Messages;
Expand Down
33 changes: 17 additions & 16 deletions server/augmented/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,31 @@
};

Rooms.count = function (callback) {
db.keys('chat:room:*', (err, keys) => {
// Use the Data helper instead of direct db.keys call
Data.count('chat:rooms', (err, count) => {
if (err) {
callback(err);
return callback(err);
}
callback(err, keys.length);
callback(null, count);
});
};

Rooms.each = function (iterator, options, callback) {
if (typeof callback === 'undefined') {
callback = options;
options = {};
}
options = options || {};
const prefix = 'chat:room:';
db.keys(`${prefix}*`, (err, keys) => {
if (err) {
return callback(err);

// Use Data.each instead of direct db.keys call
return Data.each('chat:rooms', 'chat:room:', (room, next) => {
if (room) {
// The room object should already have the roomId from Data.each
iterator(room, next);
} else {
next();
}
async.mapLimit(keys, options.batch || Data.DEFAULT_BATCH_SIZE, (key, next) => {
db.getObject(key, (err, room) => {
if (room) {
room.roomId = key.replace(prefix, '');
}
iterator(room, next);
});
}, callback);
});
}, options, callback);
};

module.exports = Rooms;
Expand Down