how to speed up docpad rendering?

65 views Asked by At

I am changing only a couple of pages but docpad seems to render everything again. I'm not using any fancy plugins or dynamic components - just the basic ghost template. Are there some techniques to make less pages render?

maybe its something to do with the timestamp format in the docpad.coffee ?

moment = require('moment')
docpadConfig = {
  templateData:
    vars:
      appserver: 'http://xxx'
    site:
      title: 'Pocket Tutor'
      tagline: 'English language chat tutor'
      description: 'Learn english by chatting'
      logo: '/uploads/images/corpid/comiceng/96/logo-96.png'
      url: 'http://app:9005'
      cover: '/img/cover.jpg'
      navigation: [
        {
          name: 'Home',
          href: '/',
          section: 'home'
        },
        {
          name: 'About',
          href: '/about.html',
          section: 'about'
        },
        {
          name: 'Lessons',
          href: '/tags/lessons.html',
          section: 'tag-lessons'
        },
        {
          name: 'Grammar',
          href: '/tags/grammar.html',
          section: 'tag-grammar'
        }
        {
          name: 'Teachers',
          href: '/tags/tech.html',
          section: 'tag-tech'
        },

      ]
    author:
      name: 'Rikai Labs'
      img: ''
      url: 'http://rikai.co'
      website: 'http://RIKAI.co'
      location: 'space',
      bio: 'we build chat apps'
    getPreparedTitle: -> if @document.title then "#{@document.title} | #{@site.title}" else @site.title
    getDescription: -> if @document.description then "#{@document.description} | #{@site.description}" else @site.description
    bodyClass: -> if @document.isPost then "post-template" else "home-template"
    masthead: (d) ->
      d = d || @document
      if d.cover then d.cover else @site.cover
    isCurrent: (l) ->
      if @document.section is l.section  then ' nav-current'
      else if @document.url is l.href then ' nav-current'
      else ''
    excerpt: (p,w) ->
      w = w || 26
      if p.excerpt then p.excerpt else p.content.replace(/<%.+%>/gi, '').split(' ').slice(0, w).join(' ')
    encode: (s) -> encodeURIComponent(s)
    slug: (s) -> return s.toLowerCase().replace(' ', '-')
    currentYear: -> new Date().getFullYear()
    time: (ts, format) ->
      format = format || 'MMMM DO, YYYY'
      ts = new Date(ts) || new Date()
      moment(ts).format(format)
  collections:
    posts: ->
      @getCollection("html").findAllLive({active:true, isPost: true, isPagedAuto: {$ne: true}}, {postDate: -1}).on "add", (model) ->
        model.setMetaDefaults({layout:"post"})
  plugins:
    tags:
      extension: '.html'
      injectDocumentHelper: (doc) ->
        doc.setMeta { layout: 'tag' }
    rss:
      default:
        collection: 'posts'
        url: '/rss.xml'
    marked:
      gfm: true

  environments:  # default
    development:  # default
        # Always refresh from server
      maxAge: false  # default
      # Only do these if we are running standalone via the `docpad` executable
      checkVersion: process.argv.length >= 2 and /docpad$/.test(process.argv[1])  # default
      welcome: process.argv.length >= 2 and /docpad$/.test(process.argv[1])  # default
      prompts: process.argv.length >= 2 and /docpad$/.test(process.argv[1])  # default

      # Listen to port 9005 on the development environment
      port: 9005  # example
    production:
      port: 9005
      maxAge: false  # default

}

module.exports = docpadConfig

update: stubbing out the date and time methods

time: -> 'time'
currentYear: -> 'year'

gives a little speed up but still making one edit to one file gives info:

Generated 40/150 files in 7.364 seconds

update2: added

standalone: true

to some pages to test, but still takes info: Generated 40/150 files in 7.252 seconds

so even a single standalone page triggers a bunch of other stuff.

1

There are 1 answers

0
Steve Mc On

It is possible to handle the Docpad regeneration process manually. To do this you need to turn off Docpad's watch. That is, run Docpad with the docpad server command. What will happen here is that it doesn't matter how many times you edit a document it will not be loaded into the docpad collection. You will then have to load any updates manually. That is, have some code to load the document.

model = @docpad.getCollection('posts').findOne({someValue: someValue})
model.load()

Following that trigger the regeneration.

 @docpad.action 'generate', reset: false, (err) ->
     if err
         @docpad.log "warn", "GENERATE ERROR"

This is what I do in my posteditor plugin

I suspect this is not really what you are asking for but it does give you full control over the regeneration process.