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

v1.18.x
psychobunny 12 years ago
parent d36a81966a
commit 523ce61d1f

@ -43,6 +43,8 @@
</li></a>
<!-- END topics -->
</ul>
<hr />
<button id="new_post" class="btn btn-primary btn-large {show_category_features}">New Topic</button>
</div>
<div class="span3 {show_category_features}">
<div class="sidebar-block img-polaroid">
@ -77,8 +79,6 @@
</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}" />

@ -1,4 +1,5 @@
var RDB = require('./redis.js'),
var RDB = require('./redis.js')
schema = require('./schema.js'),
posts = require('./posts.js'),
utils = require('./../public/src/utils.js'),
user = require('./user.js'),
@ -17,12 +18,12 @@ marked.setOptions({
Topics.getTopicById = function(tid, current_user, callback) {
function getTopicData(next) {
RDB.multi()
.get('tid:' + tid + ':title')
.get('tid:' + tid + ':locked')
.get('tid:' + tid + ':category_name')
.get('tid:' + tid + ':category_slug')
.get('tid:' + tid + ':deleted')
.get('tid:' + tid + ':pinned')
.get(schema.topics(tid).title)
.get(schema.topics(tid).locked)
.get(schema.topics(tid).category_name)
.get(schema.topics(tid).category_slug)
.get(schema.topics(tid).deleted)
.get(schema.topics(tid).pinned)
.exec(function(err, replies) {
next(null, {
topic_name: replies[0],
@ -118,14 +119,14 @@ marked.setOptions({
function get_topic_data(next) {
RDB.mget([
'tid:' + tid + ':title',
'tid:' + tid + ':uid',
'tid:' + tid + ':timestamp',
'tid:' + tid + ':slug',
'tid:' + tid + ':postcount',
'tid:' + tid + ':locked',
'tid:' + tid + ':pinned',
'tid:' + tid + ':deleted'
schema.topics(tid).title,
schema.topics(tid).uid,
schema.topics(tid).timestamp,
schema.topics(tid).slug,
schema.topics(tid).postcount,
schema.topics(tid).locked,
schema.topics(tid).pinned,
schema.topics(tid).deleted
], function(err, topic) {
if (err) {
throw new Error(err);
@ -152,7 +153,7 @@ marked.setOptions({
function get_read_status(next) {
// posts.create calls this function - should be an option to skip this because its always true
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';
next();
@ -181,7 +182,7 @@ marked.setOptions({
}
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) {
callback(cid);
} else {
@ -192,7 +193,7 @@ marked.setOptions({
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
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) {
RDB.sadd('cid:' + cid + ':read_by_uid', uid);
});
@ -202,7 +203,7 @@ marked.setOptions({
var batch = RDB.multi();
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) {
@ -230,8 +231,9 @@ marked.setOptions({
}
}
// start: probably should be moved into posts
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 = [],
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) {
if (!category_id) throw new Error('Attempted to post without a category_id');
@ -305,33 +307,33 @@ marked.setOptions({
return;
}
RDB.incr('global:next_topic_id', function(err, tid) {
RDB.incr(schema.global().next_topic_id, function(err, tid) {
RDB.handle(err);
// Global Topics
if (uid == null) uid = 0;
if (uid !== null) {
RDB.sadd('topics:tid', tid);
RDB.sadd(schema.topics().tid, tid);
} else {
// 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);
// Topic Info
RDB.set('tid:' + tid + ':title', title);
RDB.set('tid:' + tid + ':uid', uid);
RDB.set('tid:' + tid + ':slug', slug);
RDB.set('tid:' + tid + ':timestamp', new Date().getTime());
RDB.set(schema.topic(tid).title, title);
RDB.set(schema.topic(tid).uid, uid);
RDB.set(schema.topic(tid).slug, slug);
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.create(uid, tid, content, function(pid) {
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
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
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);
// 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.set('tid:' + tid + ':cid', category_id);
RDB.set(schema.topics(tid).cid, category_id);
categories.getCategories([category_id], function(data) {
RDB.set('tid:' + tid + ':category_name', data.categories[0].name);
RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug);
RDB.set(schema.topics(tid).category_name, data.categories[0].name);
RDB.set(schema.topics(tid).category_slug, data.categories[0].slug);
});
RDB.incr('cid:' + category_id + ':topiccount');

Loading…
Cancel
Save