Ind.ie is now Small Technology Foundation.
Commit 91c77811 authored by Aral Balkan's avatar Aral Balkan

Incomplete: integrate cache into builder attempt.

parent 52cfa2ee
......@@ -43,6 +43,8 @@ GlobalStatistics = require './GlobalStatistics'
require './StringExtensions' # for String::trim()
crypto = require 'crypto'
class Blockdown
......@@ -1173,4 +1175,13 @@ Better is a Safari content blocker for <a href='https://itunes.apple.com/us/app/
expect(validValues.size, "All #{parentObjectsHumanName} #{propertysHumanName} values should be valid.").to.equal actualValues.size
#
# Calculate checksum
#
checksum = (str) ->
return crypto
.createHash('md5')
.update(str, 'utf8')
.digest('hex')
module.exports = Blockdown
......@@ -30,6 +30,8 @@ exec = (require 'child_process').exec
touch = require 'touch'
cache = require './Cache2'
class Builder
instance = null
......
......@@ -20,18 +20,30 @@ class Cache
cacheCurrentChecksumsDirectory: null
lastModifiedTimes: null
constructor: ->
@homeDirectory = path.join path.homedir(), 'better.fyi'
@contentDirectory = path.join @homeDirectory, 'content'
@themesDirectory = path.join @homeDirectory, 'themes'
@cacheCurrentModifiedTimesFile = path.join @homeDirectory, '.private', 'cache', 'current-modified-times.json'
@cachePreviousModifiedTimesFile = path.join @homeDirectory, '.private', 'cache', 'previous-modified-times.json'
@lastModifiedTimes = {}
build: =>
startTime = new Date
# Back up the current modified times file
if fs.existsSync @cacheCurrentModifiedTimesFile
fs.copySync @cacheCurrentModifiedTimesFile, @cachePreviousModifiedTimesFile
@cacheContent @contentDirectory
.then =>
@cacheContent @themesDirectory
.then =>
fs.outputFileAsync @cacheCurrentModifiedTimesFile, JSON.stringify @lastModifiedTimes, null, " "
.then =>
duration = (new Date) - startTime
console.log "Took: #{duration} ms"
......@@ -39,8 +51,6 @@ class Cache
cacheContent: (directory) =>
lastModifiedTimes = {}
(globAsync "#{directory}/**/*", {nodir: true})
.series (file) =>
......@@ -49,8 +59,11 @@ class Cache
# Using the sync version of stat is a little faster here
stats = fs.statSync file
lastModifiedTimes[filePathFragment] = stats.mtime
.then =>
fs.outputFileAsync @cacheCurrentModifiedTimesFile, JSON.stringify lastModifiedTimes
@lastModifiedTimes[filePathFragment] = stats.mtime
module.exports = Cache
# Test
cache = new Cache
cache.build()
new Cache
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment