From 4ab2d4c337ad5d1f1eca29c72c83bc99448e7ef6 Mon Sep 17 00:00:00 2001 From: alsotang Date: Sat, 4 Apr 2015 18:30:45 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=BC=93=E5=AD=98=E6=97=A0=E6=95=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/site.js | 41 +++++------------------------------ public/stylesheets/style.less | 4 ---- test/common/cache.test.js | 2 +- views/topic/index.html | 13 ----------- 4 files changed, 7 insertions(+), 53 deletions(-) diff --git a/controllers/site.js b/controllers/site.js index 7017299..47ef0f7 100644 --- a/controllers/site.js +++ b/controllers/site.js @@ -16,32 +16,7 @@ var eventproxy = require('eventproxy'); var cache = require('../common/cache'); var xmlbuilder = require('xmlbuilder'); var renderHelper = require('../common/render_helper'); - -// 主页的缓存工作。主页是需要主动缓存的 -function indexCache() { - if (config.debug) { - return; - } - var limit = config.list_topic_count; - // 为所有版块(tab)做缓存 - [['', '全部']].concat(config.tabs).forEach(function (pair) { - // 只缓存第一页, page = 1。options 之所以每次都生成是因为 mongoose 查询时, - // 会改动它 - var options = { skip: (1 - 1) * limit, limit: limit, sort: '-top -last_reply_at'}; - var tabValue = pair[0]; - var query = {}; - if (tabValue) { - query.tab = tabValue; - } - var optionsStr = JSON.stringify(query) + JSON.stringify(options); - Topic.getTopicsByQuery(query, options, function (err, topics) { - cache.set(optionsStr, topics); - }); - }); -} -setInterval(indexCache, 1000 * 5); // 五秒更新一次 -indexCache(); -// END 主页的缓存工作 +var _ = require('lodash'); exports.index = function (req, res, next) { var page = parseInt(req.query.page, 10) || 1; @@ -63,17 +38,10 @@ exports.index = function (req, res, next) { var limit = config.list_topic_count; var options = { skip: (page - 1) * limit, limit: limit, sort: '-top -last_reply_at'}; - var optionsStr = JSON.stringify(query) + JSON.stringify(options); - cache.get(optionsStr, proxy.done(function (topics) { - if (topics) { - return proxy.emit('topics', topics); - } - Topic.getTopicsByQuery(query, options, proxy.done('topics', function (topics) { - return topics; - })); + Topic.getTopicsByQuery(query, options, proxy.done('topics', function (topics) { + return topics; })); - // END 取主题 // 取排行榜上的用户 cache.get('tops', proxy.done(function (tops) { @@ -93,6 +61,7 @@ exports.index = function (req, res, next) { ); } })); + // END 取排行榜上的用户 // 取0回复的主题 cache.get('no_reply_topics', proxy.done(function (no_reply_topics) { @@ -108,6 +77,7 @@ exports.index = function (req, res, next) { })); } })); + // END 取0回复的主题 // 取分页数据 cache.get('pages', proxy.done(function (pages) { @@ -121,6 +91,7 @@ exports.index = function (req, res, next) { })); } })); + // END 取分页数据 var tabName = renderHelper.tabName(tab); proxy.all('topics', 'tops', 'no_reply_topics', 'pages', diff --git a/public/stylesheets/style.less b/public/stylesheets/style.less index c3e69bc..f2436cb 100644 --- a/public/stylesheets/style.less +++ b/public/stylesheets/style.less @@ -1257,10 +1257,6 @@ textarea.editor { height: 200px; } -.jiathis_style_24x24 { - display: inline-block; -} - .cnode-app-download { text-align: center; } diff --git a/test/common/cache.test.js b/test/common/cache.test.js index 2cf39fd..7235be5 100644 --- a/test/common/cache.test.js +++ b/test/common/cache.test.js @@ -1,7 +1,7 @@ var cache = require('../../common/cache'); var should = require('should'); -describe.only('test/common/cache.test.js', function () { +describe('test/common/cache.test.js', function () { it('should set && get', function (done) { cache.set('alsotang', {age: 23}, function () { cache.get('alsotang', function (err, data) { diff --git a/views/topic/index.html b/views/topic/index.html index a60b24f..9023634 100644 --- a/views/topic/index.html +++ b/views/topic/index.html @@ -134,19 +134,6 @@
<%- markdown(topic.linkedContent) %>
-
- -
- - - - - - -
- - -
<% if (topic.replies && topic.replies.length > 0) { %>