<commit_before>/**
 * Copyright (c) 2015 <NAME> (@localnerve), LocalNerve LLC
 * Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
 */
'use strict';

var debug = require('debug')('Example:PageAction');
var ContentStore = require('../stores/ContentStore');
var defaultPageTitle = 'Default Page Title';

function dispatchActions(context, resource, title, content) {
  context.dispatch('RECEIVE_PAGE_CONTENT', {
    resource: resource,
    content: content
  });

  context.dispatch('UPDATE_PAGE_TITLE', {
    title: title
  });  
}

function page(context, payload, done) {
  var title = (payload.pageTitle || defaultPageTitle);

  // Try cache first
  var content = context.getStore(ContentStore).get(payload.resource);
  if (content) {
    debug('Found '+payload.resource+' in cache');
    dispatchActions(context, payload.resource, title, content);
  }

  debug('Page service request start');
  context.service.read('page', payload, {}, function(err, data) {
    debug('Page service request complete');

    if (err) {
      return done(err);
    }

    if (!data) {
      var noData = new Error('Page not found');
      noData.statusCode = 404;
      return done(noData);
    }

    dispatchActions(context, payload.resource, title, data);

    return done();
  });  
}

module.exports = page;<commit_msg>fix content caching<commit_after>/**
 * Copyright (c) 2015 <NAME> (@localnerve), LocalNerve LLC
 * Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
 */
'use strict';

var debug = require('debug')('Example:PageAction');
var ContentStore = require('../stores/ContentStore');
var defaultPageTitle = 'Default Page Title';

function dispatchActions(context, resource, title, content) {
  context.dispatch('RECEIVE_PAGE_CONTENT', {
    resource: resource,
    content: content
  });

  context.dispatch('UPDATE_PAGE_TITLE', {
    title: title
  });  
}

function serviceRequest(context, payload, done) {
  debug('Page service request start');

  context.service.read('page', payload, {}, function(err, data) {
    debug('Page service request complete');

    if (err) {
      return done(err);
    }

    if (!data) {
      var noData = new Error('Page not found');
      noData.statusCode = 404;
      return done(noData);
    }

    dispatchActions(context, payload.resource, payload.pageTitle, data);

    return done();
  });
}

function page(context, payload, done) {
  payload.pageTitle = payload.pageTitle || defaultPageTitle;

  var content = context.getStore(ContentStore).get(payload.resource);
  if (content) {
    debug('Found '+payload.resource+' in cache');
    dispatchActions(context, payload.resource, payload.pageTitle, content);
    return done();
  }

  serviceRequest(context, payload, done);
}

module.exports = page;
{'fraction_non_alphanumeric': 0.13671875, 'fraction_numerical': 0.004971590909090909, 'mean_word_length': 4.0303571428571425, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4843591', 'n_tokens_mistral': 834, 'n_tokens_neox': 800, 'n_words': 220}