Permalink
Browse files

Attempt at caching the entire database. Something is going wrong with…

… the re-load. DocPad complains about null outPath conflicts.
  • Loading branch information...
balupton committed Nov 24, 2013
1 parent b8d3313 commit 80d4305dc54870e333029826e258eb16f8cbebcb
Showing with 24 additions and 4 deletions.
  1. +2 −1 .gitignore
  2. +22 −3 src/lib/docpad.coffee
View
@@ -15,4 +15,5 @@ out/
# =====================================
# PROJECT SPECIFIC FILES
-test/render-out/
+test/render-out/
+test/.docpad.db
View
@@ -782,6 +782,9 @@ class DocPad extends EventEmitterGrouped
# The project directory
rootPath: process.cwd()
+ # The project's database path
+ databasePath: '.docpad.db'
+
# The project's package.json path
packagePath: 'package.json'
@@ -1429,6 +1432,8 @@ class DocPad extends EventEmitterGrouped
@config.rootPath = pathUtil.resolve(@config.rootPath)
@config.outPath = pathUtil.resolve(@config.rootPath, @config.outPath)
@config.srcPath = pathUtil.resolve(@config.rootPath, @config.srcPath)
+ @config.databasePath = pathUtil.resolve(@config.rootPath, @config.databasePath)
+ @config.packagePath = pathUtil.resolve(@config.rootPath, @config.packagePath)
# Resolve Documents, Files, Layouts paths
for type in ['documents','files','layouts']
@@ -3236,19 +3241,20 @@ class DocPad extends EventEmitterGrouped
docpad = @
config = docpad.getConfig()
locale = docpad.getLocale()
- lastGenerateStarted = docpad.generateStarted
database = docpad.getDatabase()
# Check
return next() if opts.collection?.length is 0
# Update generating flag
+ lastGenerateStarted = docpad.generateStarted
docpad.generateStarted = new Date()
+ docpad.generateEnded = null
docpad.generating = true
# Update the cached database
- docpad.databaseCache = new FilesCollection(database.models)
+ docpad.databaseCache = new FilesCollection(database.models) if database.models.length
# Destroy Regenerate Timer
docpad.destroyRegenerateTimer()
@@ -3304,14 +3310,21 @@ class DocPad extends EventEmitterGrouped
docpad.destroyProgress(opts.progress)
opts.progress = null
+ # Dump the database
+ databaseCache =
+ generateStarted: docpad.generateStarted
+ generateEnded: docpad.generateEnded
+ models: docpad.getDatabase().toJSON()
+ require('fs').writeFileSync(config.databasePath, JSON.stringify(databaseCache, null, ' '))
+
# Prepare
seconds = (docpad.generateEnded - docpad.generateStarted) / 1000
howMany = "#{opts.collection?.length or 0}/#{database.length}"
# Log
opts.progress?.finish()
docpad.log 'info', util.format(locale.renderGenerated, howMany, seconds)
- docpad.notify (new Date()).toLocaleTimeString(), title: locale.renderGeneratedNotification
+ docpad.notify (new Date()).toLocaleTimeString(), {title: locale.renderGeneratedNotification}
# Forward
return next(err)
@@ -3346,6 +3359,12 @@ class DocPad extends EventEmitterGrouped
addTask 'Reset our collections', (complete) ->
docpad.resetCollections(opts, complete)
+ if require('fs').existsSync(config.databasePath)
+ console.log 'Loading cached database'
+ databaseData = JSON.parse require('fs').readFileSync(config.databasePath)
+ lastGenerateStarted = databaseData.generateStarted
+ database.add(databaseData.models)
+ console.log 'Added', databaseData.models.length
# Do we want to pull in new data?
if opts.reset is true

0 comments on commit 80d4305

Please sign in to comment.