1 less db call in togglePin

v1.18.x
barisusakli 10 years ago
parent 467fb1ab4a
commit 5f8781c88e

@ -134,12 +134,10 @@ var winston = require('winston'),
emitTo('topic_' + tid); emitTo('topic_' + tid);
emitTo('category_' + cid); emitTo('category_' + cid);
if (typeof callback === 'function') { callback(null, {
callback(null, { tid: tid,
tid: tid, isLocked: lock
isLocked: lock });
});
}
}); });
} }
@ -152,7 +150,7 @@ var winston = require('winston'),
}; };
function togglePin(tid, uid, pin, callback) { function togglePin(tid, uid, pin, callback) {
topics.getTopicField(tid, 'cid', function(err, cid) { topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) {
function emitTo(room) { function emitTo(room) {
websockets.in(room).emit(pin ? 'event:topic_pinned' : 'event:topic_unpinned', { websockets.in(room).emit(pin ? 'event:topic_pinned' : 'event:topic_unpinned', {
tid: tid, tid: tid,
@ -165,9 +163,7 @@ var winston = require('winston'),
} }
topics.setTopicField(tid, 'pinned', pin ? 1 : 0); topics.setTopicField(tid, 'pinned', pin ? 1 : 0);
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) { db.sortedSetAdd('cid:' + topicData.cid + ':tids', pin ? Math.pow(2, 53) : topicData.lastposttime, tid);
db.sortedSetAdd('cid:' + topicData.cid + ':tids', pin ? Math.pow(2, 53) : topicData.lastposttime, tid);
});
plugins.fireHook('action:topic.pin', { plugins.fireHook('action:topic.pin', {
tid: tid, tid: tid,
@ -176,14 +172,12 @@ var winston = require('winston'),
}); });
emitTo('topic_' + tid); emitTo('topic_' + tid);
emitTo('category_' + cid); emitTo('category_' + topicData.cid);
if (typeof callback === 'function') { callback(null, {
callback(null, { tid: tid,
tid: tid, isPinned: pin
isPinned: pin });
});
}
}); });
} }

Loading…
Cancel
Save