redis schema file for organization; moved new topic button in categories higher

v1.18.x
psychobunny
parent d36a81966a
commit 523ce61d1f

@ -43,6 +43,8 @@
</li></a> </li></a>
<!-- END topics --> <!-- END topics -->
</ul> </ul>
<hr />
<button id="new_post" class="btn btn-primary btn-large {show_category_features}">New Topic</button>
</div> </div>
<div class="span3 {show_category_features}"> <div class="span3 {show_category_features}">
<div class="sidebar-block img-polaroid"> <div class="sidebar-block img-polaroid">
@ -77,8 +79,6 @@
</div> </div>
<hr />
<button id="new_post" class="btn btn-primary btn-large {show_category_features}">New Topic</button>
<input type="hidden" template-variable="category_id" value="{category_id}" /> <input type="hidden" template-variable="category_id" value="{category_id}" />

@ -1,4 +1,5 @@
var RDB = require('./redis.js'), var RDB = require('./redis.js')
schema = require('./schema.js'),
posts = require('./posts.js'), posts = require('./posts.js'),
utils = require('./../public/src/utils.js'), utils = require('./../public/src/utils.js'),
user = require('./user.js'), user = require('./user.js'),
@ -17,12 +18,12 @@ marked.setOptions({
Topics.getTopicById = function(tid, current_user, callback) { Topics.getTopicById = function(tid, current_user, callback) {
function getTopicData(next) { function getTopicData(next) {
RDB.multi() RDB.multi()
.get('tid:' + tid + ':title') .get(schema.topics(tid).title)
.get('tid:' + tid + ':locked') .get(schema.topics(tid).locked)
.get('tid:' + tid + ':category_name') .get(schema.topics(tid).category_name)
.get('tid:' + tid + ':category_slug') .get(schema.topics(tid).category_slug)
.get('tid:' + tid + ':deleted') .get(schema.topics(tid).deleted)
.get('tid:' + tid + ':pinned') .get(schema.topics(tid).pinned)
.exec(function(err, replies) { .exec(function(err, replies) {
next(null, { next(null, {
topic_name: replies[0], topic_name: replies[0],
@ -118,14 +119,14 @@ marked.setOptions({
function get_topic_data(next) { function get_topic_data(next) {
RDB.mget([ RDB.mget([
'tid:' + tid + ':title', schema.topics(tid).title,
'tid:' + tid + ':uid', schema.topics(tid).uid,
'tid:' + tid + ':timestamp', schema.topics(tid).timestamp,
'tid:' + tid + ':slug', schema.topics(tid).slug,
'tid:' + tid + ':postcount', schema.topics(tid).postcount,
'tid:' + tid + ':locked', schema.topics(tid).locked,
'tid:' + tid + ':pinned', schema.topics(tid).pinned,
'tid:' + tid + ':deleted' schema.topics(tid).deleted
], function(err, topic) { ], function(err, topic) {
if (err) { if (err) {
throw new Error(err); throw new Error(err);
@ -152,7 +153,7 @@ marked.setOptions({
function get_read_status(next) { function get_read_status(next) {
// posts.create calls this function - should be an option to skip this because its always true // posts.create calls this function - should be an option to skip this because its always true
if (uid && parseInt(uid) > 0) { if (uid && parseInt(uid) > 0) {
RDB.sismember('tid:' + tid + ':read_by_uid', uid, function(err, read) { RDB.sismember(schema.topics(tid).read_by_uid, uid, function(err, read) {
topicData.badgeclass = read ? '' : 'badge-important'; topicData.badgeclass = read ? '' : 'badge-important';
next(); next();
@ -181,7 +182,7 @@ marked.setOptions({
} }
Topics.get_cid_by_tid = function(tid, callback) { Topics.get_cid_by_tid = function(tid, callback) {
RDB.get('tid:' + tid + ':cid', function(err, cid) { RDB.get(schema.topics(tid).cid, function(err, cid) {
if (cid && parseInt(cid) > 0) { if (cid && parseInt(cid) > 0) {
callback(cid); callback(cid);
} else { } else {
@ -192,7 +193,7 @@ marked.setOptions({
Topics.markAsRead = function(tid, uid) { Topics.markAsRead = function(tid, uid) {
// there is an issue with this fn. if you read a topic that is previously read you will mark the category as read anyways - there is no check // there is an issue with this fn. if you read a topic that is previously read you will mark the category as read anyways - there is no check
RDB.sadd('tid:' + tid + ':read_by_uid', uid); RDB.sadd(schema.topics(tid).read_by_uid, uid);
Topics.get_cid_by_tid(tid, function(cid) { Topics.get_cid_by_tid(tid, function(cid) {
RDB.sadd('cid:' + cid + ':read_by_uid', uid); RDB.sadd('cid:' + cid + ':read_by_uid', uid);
}); });
@ -202,7 +203,7 @@ marked.setOptions({
var batch = RDB.multi(); var batch = RDB.multi();
for (var i=0, ii=tids.length; i<ii; i++) { for (var i=0, ii=tids.length; i<ii; i++) {
batch.sismember('tid:' + tids[i] + ':read_by_uid', uid); batch.sismember(schema.topics(tids[i]).read_by_uid, uid);
} }
batch.exec(function(err, hasRead) { batch.exec(function(err, hasRead) {
@ -230,8 +231,9 @@ marked.setOptions({
} }
} }
// start: probably should be moved into posts
Topics.get_latest_undeleted_pid = function(tid, callback) { Topics.get_latest_undeleted_pid = function(tid, callback) {
RDB.lrange('tid:' + tid + ':posts', 0, -1, function(err, pids) { RDB.lrange(schema.topics(tid).posts, 0, -1, function(err, pids) {
var pidKeys = [], var pidKeys = [],
numPids = pids.length; numPids = pids.length;
@ -275,7 +277,7 @@ marked.setOptions({
} }
}); });
} }
// end: probably should be moved into posts
Topics.post = function(socket, uid, title, content, category_id) { Topics.post = function(socket, uid, title, content, category_id) {
if (!category_id) throw new Error('Attempted to post without a category_id'); if (!category_id) throw new Error('Attempted to post without a category_id');
@ -305,33 +307,33 @@ marked.setOptions({
return; return;
} }
RDB.incr('global:next_topic_id', function(err, tid) { RDB.incr(schema.global().next_topic_id, function(err, tid) {
RDB.handle(err); RDB.handle(err);
// Global Topics // Global Topics
if (uid == null) uid = 0; if (uid == null) uid = 0;
if (uid !== null) { if (uid !== null) {
RDB.sadd('topics:tid', tid); RDB.sadd(schema.topics().tid, tid);
} else { } else {
// need to add some unique key sent by client so we can update this with the real uid later // need to add some unique key sent by client so we can update this with the real uid later
RDB.lpush('topics:queued:tid', tid); RDB.lpush(schema.topics().queued_tids, tid);
} }
var slug = tid + '/' + utils.slugify(title); var slug = tid + '/' + utils.slugify(title);
// Topic Info // Topic Info
RDB.set('tid:' + tid + ':title', title); RDB.set(schema.topic(tid).title, title);
RDB.set('tid:' + tid + ':uid', uid); RDB.set(schema.topic(tid).uid, uid);
RDB.set('tid:' + tid + ':slug', slug); RDB.set(schema.topic(tid).slug, slug);
RDB.set('tid:' + tid + ':timestamp', new Date().getTime()); RDB.set(schema.topic(tid).timestamp, new Date().getTime());
RDB.set('topic:slug:' + slug + ':tid', tid); RDB.set(schema.topic().slug(slug).tid, tid);
// Posts // Posts
posts.create(uid, tid, content, function(pid) { posts.create(uid, tid, content, function(pid) {
if (pid > 0) { if (pid > 0) {
RDB.lpush('tid:' + tid + ':posts', pid); RDB.lpush(schema.topic(tid).posts, pid);
// Notify any users looking at the category that a new topic has arrived // Notify any users looking at the category that a new topic has arrived
Topics.get_topic(tid, uid, function(topicData) { Topics.get_topic(tid, uid, function(topicData) {
@ -355,15 +357,15 @@ marked.setOptions({
// let everyone know that there is an unread topic in this category // let everyone know that there is an unread topic in this category
RDB.del('cid:' + category_id + ':read_by_uid'); RDB.del('cid:' + category_id + ':read_by_uid');
RDB.zadd('topics:recent', (new Date()).getTime(), tid); RDB.zadd(schema.topics().recent, (new Date()).getTime(), tid);
//RDB.zadd('topics:active', tid); //RDB.zadd('topics:active', tid);
// in future it may be possible to add topics to several categories, so leaving the door open here. // 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); RDB.sadd('categories:' + category_id + ':tid', tid);
RDB.set('tid:' + tid + ':cid', category_id); RDB.set(schema.topics(tid).cid, category_id);
categories.getCategories([category_id], function(data) { categories.getCategories([category_id], function(data) {
RDB.set('tid:' + tid + ':category_name', data.categories[0].name); RDB.set(schema.topics(tid).category_name, data.categories[0].name);
RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug); RDB.set(schema.topics(tid).category_slug, data.categories[0].slug);
}); });
RDB.incr('cid:' + category_id + ':topiccount'); RDB.incr('cid:' + category_id + ':topiccount');

Loading…
Cancel
Save