mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 20:45:58 +01:00
refactor to remove category_name and category_slug from topic hashes
This commit is contained in:
@@ -41,25 +41,12 @@ var RDB = require('./../redis.js'),
|
||||
var slug = cid + '/' + utils.slugify(category[key]);
|
||||
RDB.hset('category:' + cid, 'slug', slug);
|
||||
RDB.set('categoryslug:' + slug + ':cid', cid);
|
||||
|
||||
RDB.smembers('categories:' + cid + ':tid', function(err, tids) {
|
||||
var pipe = RDB.multi();
|
||||
|
||||
for (var tid in tids) {
|
||||
pipe.set(schema.topics(tid).category_name, category[key]);
|
||||
pipe.set(schema.topics(tid).category_slug, slug);
|
||||
}
|
||||
pipe.exec();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
updated.push(cid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
socket.emit('event:alert', {
|
||||
title: 'Updated Categories',
|
||||
message: 'Category IDs ' + updated.join(', ') + ' was successfully updated.',
|
||||
|
||||
@@ -9,9 +9,9 @@ var RDB = require('./redis.js'),
|
||||
|
||||
Categories.getCategoryById = function(category_id, current_user, callback) {
|
||||
|
||||
Categories.getCategoryData(category_id, function(categoryData) {
|
||||
Categories.getCategoryData(category_id, function(err, categoryData) {
|
||||
|
||||
if(!categoryData) {
|
||||
if(err) {
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
@@ -341,9 +341,20 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
|
||||
Categories.getCategoryData = function(cid, callback) {
|
||||
RDB.hgetall('category:' + cid, function(err, data) {
|
||||
if(err === null)
|
||||
callback(data);
|
||||
RDB.hgetall('category:' + cid, callback);
|
||||
}
|
||||
|
||||
Categories.getCategoryFields = function(cid, fields, callback) {
|
||||
RDB.hmget('category:' + cid, fields, function(err, data) {
|
||||
if(err === null) {
|
||||
var returnData = {};
|
||||
|
||||
for(var i=0, ii=fields.length; i<ii; ++i) {
|
||||
returnData[fields[i]] = data[i];
|
||||
}
|
||||
|
||||
callback(returnData);
|
||||
}
|
||||
else
|
||||
console.log(err);
|
||||
});
|
||||
@@ -366,9 +377,9 @@ var RDB = require('./redis.js'),
|
||||
var categories = [];
|
||||
|
||||
for(var i=0; i<cids.length; ++i) {
|
||||
Categories.getCategoryData(cids[i], function(categoryData) {
|
||||
Categories.getCategoryData(cids[i], function(err, categoryData) {
|
||||
|
||||
if(!categoryData)
|
||||
if(err)
|
||||
return;
|
||||
|
||||
Categories.hasReadCategory(categoryData.cid, current_user, function(hasRead) {
|
||||
|
||||
@@ -180,11 +180,6 @@ var RDB = require('./redis.js'),
|
||||
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1);
|
||||
categories.incrementCategoryFieldBy(cid, 'topic_count', 1);
|
||||
|
||||
categories.getCategories([cid], function(data) {
|
||||
topics.setTopicField(tid, 'category_name', data.categories[0].name);
|
||||
topics.setTopicField(tid, 'category_slug', data.categories[0].slug);
|
||||
});
|
||||
|
||||
socket.emit('api:topic.move', {
|
||||
status: 'ok'
|
||||
});
|
||||
|
||||
@@ -84,9 +84,16 @@ marked.setOptions({
|
||||
});
|
||||
}
|
||||
|
||||
Topics.getCategoryData = function(tid, callback) {
|
||||
Topics.getTopicField(tid, 'cid', function(cid) {
|
||||
categories.getCategoryData(cid, callback);
|
||||
});
|
||||
}
|
||||
|
||||
Topics.getTopicWithPosts = function(tid, current_user, callback) {
|
||||
threadTools.exists(tid, function(exists) {
|
||||
if (!exists) return callback(new Error('Topic tid \'' + tid + '\' not found'));
|
||||
if (!exists)
|
||||
return callback(new Error('Topic tid \'' + tid + '\' not found'));
|
||||
|
||||
Topics.markAsRead(tid, current_user);
|
||||
|
||||
@@ -109,18 +116,28 @@ marked.setOptions({
|
||||
});
|
||||
}
|
||||
|
||||
async.parallel([getTopicData, getTopicPosts, getPrivileges], function(err, results) {
|
||||
if (err) console.log(err.message);
|
||||
function getCategoryData(next) {
|
||||
Topics.getCategoryData(tid, next);
|
||||
}
|
||||
|
||||
async.parallel([getTopicData, getTopicPosts, getPrivileges, getCategoryData], function(err, results) {
|
||||
if (err) {
|
||||
console.log(err.message);
|
||||
callback(err, null);
|
||||
return;
|
||||
}
|
||||
|
||||
var topicData = results[0],
|
||||
topicPosts = results[1],
|
||||
privileges = results[2];
|
||||
privileges = results[2],
|
||||
categoryData = results[3];
|
||||
|
||||
var main_posts = topicPosts.splice(0, 1);
|
||||
|
||||
callback(null, {
|
||||
'topic_name':topicData.title,
|
||||
'category_name':topicData.category_name,
|
||||
'category_slug':topicData.category_slug,
|
||||
'category_name':categoryData.name,
|
||||
'category_slug':categoryData.slug,
|
||||
'locked': topicData.locked,
|
||||
'deleted': topicData.deleted,
|
||||
'pinned': topicData.pinned,
|
||||
@@ -410,12 +427,6 @@ marked.setOptions({
|
||||
|
||||
// in future it may be possible to add topics to several categories, so leaving the door open here.
|
||||
RDB.sadd('categories:' + category_id + ':tid', tid);
|
||||
|
||||
categories.getCategories([category_id], function(data) {
|
||||
Topics.setTopicField(tid, 'category_name', data.categories[0].name);
|
||||
Topics.setTopicField(tid, 'category_slug', data.categories[0].slug);
|
||||
});
|
||||
|
||||
RDB.hincrby('category:' + category_id, 'topic_count', 1);
|
||||
RDB.incr('totaltopiccount');
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ var express = require('express'),
|
||||
// Middlewares
|
||||
app.use(express.favicon(path.join(__dirname, '../', 'public', 'favicon.ico')));
|
||||
app.use(require('less-middleware')({ src: path.join(__dirname, '../', 'public') }));
|
||||
//app.use(express.static(path.join(__dirname, '../', 'public')));
|
||||
app.use(global.nconf.get('relative_path'), express.static(path.join(__dirname, '../', 'public')));
|
||||
app.use(express.bodyParser()); // Puts POST vars in request.body
|
||||
app.use(express.cookieParser()); // If you want to parse cookies (res.cookies)
|
||||
@@ -252,7 +251,7 @@ var express = require('express'),
|
||||
app.get('/api/:method/:id*', api_method);
|
||||
|
||||
app.get('/cid/:cid', function(req, res) {
|
||||
categories.getCategoryData(req.params.cid, function(data){
|
||||
categories.getCategoryData(req.params.cid, function(err, data) {
|
||||
if(data)
|
||||
res.send(data);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user