mirror of
https://github.com/wassname/talk.git
synced 2026-08-11 11:27:10 +08:00
redis optim
- removes call for comment count when we already have totalCommentCount - removes job processor cleaner on non-processing nodes - fixed some template issues
This commit is contained in:
@@ -38,7 +38,7 @@ function applyToCommentsOrigin(root, callback) {
|
||||
function findAndInsertComment(parent, comment) {
|
||||
const isAsset = parent.__typename === 'Asset';
|
||||
const [connectionField, countField, action] = isAsset
|
||||
? ['comments', 'commentCount', '$unshift']
|
||||
? ['comments', 'totalCommentCount', '$unshift']
|
||||
: ['replies', 'replyCount', '$push'];
|
||||
|
||||
if (
|
||||
@@ -79,7 +79,7 @@ export function insertCommentIntoEmbedQuery(root, comment) {
|
||||
|
||||
function findAndRemoveComment(parent, id) {
|
||||
const [connectionField, countField] = parent.__typename === 'Asset'
|
||||
? ['comments', 'commentCount']
|
||||
? ['comments', 'totalCommentCount']
|
||||
: ['replies', 'replyCount'];
|
||||
|
||||
const connection = parent[connectionField];
|
||||
|
||||
@@ -324,7 +324,6 @@ const fragments = {
|
||||
charCount
|
||||
requireEmailConfirmation
|
||||
}
|
||||
commentCount @skip(if: $hasComment)
|
||||
totalCommentCount @skip(if: $hasComment)
|
||||
comments(query: {limit: 10, excludeIgnored: $excludeIgnored, sortOrder: $sortOrder, sortBy: $sortBy}) @skip(if: $hasComment) {
|
||||
nodes {
|
||||
@@ -345,7 +344,6 @@ const fragments = {
|
||||
const mapStateToProps = (state) => ({
|
||||
auth: state.auth,
|
||||
refetching: state.embed.refetching,
|
||||
commentCountCache: state.stream.commentCountCache,
|
||||
activeReplyBox: state.stream.activeReplyBox,
|
||||
commentId: state.stream.commentId,
|
||||
assetId: state.stream.assetId,
|
||||
|
||||
@@ -24,6 +24,10 @@ const CONFIG = {
|
||||
// indexes.
|
||||
CREATE_MONGO_INDEXES: process.env.DISABLE_CREATE_MONGO_INDEXES !== 'TRUE',
|
||||
|
||||
// SETTINGS_CACHE_TIME is the time that we'll cache the settings in redis before
|
||||
// fetching again.
|
||||
SETTINGS_CACHE_TIME: ms(process.env.TALK_SETTINGS_CACHE_TIME || '1hr'),
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// JWT based configuration
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
+2
-2
@@ -110,9 +110,9 @@ router.use('/api/v1/graph/ql', apollo.graphqlExpress(createGraphOptions));
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
|
||||
// Interactive graphiql interface.
|
||||
router.use('/api/v1/graph/iql', (req, res) => {
|
||||
router.use('/api/v1/graph/iql', staticTemplate, (req, res) => {
|
||||
res.render('graphiql', {
|
||||
endpointURL: `${req.app.locals.BASE_URL}api/v1/graph/ql`
|
||||
endpointURL: 'api/v1/graph/ql'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+15
-4
@@ -9,7 +9,8 @@ const kue = require('kue');
|
||||
// singleton Queue instance. So you can configure and use only a single Queue
|
||||
// object within your node.js process.
|
||||
let queue = null;
|
||||
const getQueue = () => {
|
||||
let isManaging = false;
|
||||
const getQueue = ({managed = false} = {}) => {
|
||||
if (queue) {
|
||||
return queue;
|
||||
}
|
||||
@@ -21,8 +22,16 @@ const getQueue = () => {
|
||||
}
|
||||
});
|
||||
|
||||
// Watch for stuck jobs to manage.
|
||||
queue.watchStuckJobs(1000);
|
||||
// If this is a managed queue, and we aren't managing yet, then start the
|
||||
// management.
|
||||
if (managed && !isManaging) {
|
||||
|
||||
// Watch for stuck jobs to manage.
|
||||
queue.watchStuckJobs(60000);
|
||||
|
||||
// Mark that we've now started management routines.
|
||||
isManaging = true;
|
||||
}
|
||||
|
||||
return queue;
|
||||
};
|
||||
@@ -67,7 +76,9 @@ class Task {
|
||||
* Process jobs for the queue.
|
||||
*/
|
||||
process(callback) {
|
||||
return getQueue().process(this.name, callback);
|
||||
|
||||
// Get the queue in managed mode.
|
||||
return getQueue({managed: true}).process(this.name, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@ const SettingModel = require('../models/setting');
|
||||
const cache = require('./cache');
|
||||
const errors = require('../errors');
|
||||
const {dotize} = require('./utils');
|
||||
const {SETTINGS_CACHE_TIME} = require('../config');
|
||||
|
||||
/**
|
||||
* The selector used to uniquely identify the settings document.
|
||||
@@ -35,7 +36,7 @@ module.exports = class SettingsService {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
|
||||
// When in production, wrap the settings retrieval with a cache.
|
||||
const settings = await cache.h.wrap('settings', fields, 60, () => retrieve(fields));
|
||||
const settings = await cache.h.wrap('settings', fields, SETTINGS_CACHE_TIME / 1000, () => retrieve(fields));
|
||||
|
||||
return new SettingModel(settings);
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@
|
||||
}
|
||||
}
|
||||
// We don't use safe-serialize for location, because it's not client input.
|
||||
var fetchURL = locationQuery(otherParams, '<%= endpointURL %>');
|
||||
var fetchURL = locationQuery(otherParams, '<%= BASE_URL %><%= endpointURL %>');
|
||||
|
||||
// Defines a GraphQL fetcher using the fetch API.
|
||||
function graphQLFetcher(graphQLParams) {
|
||||
|
||||
Reference in New Issue
Block a user