Verified Commit b97d4383 authored by Aral Balkan's avatar Aral Balkan
Browse files

Now saving out statistics in the metadata file

parent 7eaa6264
......@@ -797,6 +797,15 @@ Better is a Safari content blocker for <a href='https://itunes.apple.com/us/app/
# Saves the WebKit content blocking rule file, blockerList.json.
#
saveBlockerListJSON: (dataDirectory) =>
if @contentHasNotChanged
console.log("\t✓ Content has not changed. Not saving blocker list JSON or its metadata file.")
return Promise.resolve()
#
# Content has changed. Save the blocker list and metadata files.
#
blockerListJSONFilePath = path.join dataDirectory, 'blockerList.json'
metadataFilePath = path.join dataDirectory, 'metadata.json'
......@@ -806,6 +815,8 @@ Better is a Safari content blocker for <a href='https://itunes.apple.com/us/app/
output = JSON.stringify.apply @, args
hash = checksum(output)
# TODO: Only update metadata if rules have been updated.
#
# Prepare metadata
#
......@@ -854,26 +865,36 @@ Better is a Safari content blocker for <a href='https://itunes.apple.com/us/app/
if (key.indexOf SITES) > -1
trackersDeleted.add uniqueIdentifier
console.log("Rules added: #{rulesAdded.size}")
rulesChanged = rulesAdded.size + rulesUpdated.size + rulesDeleted.size
trackersChanged = trackersAdded.size + trackersUpdated.size + trackersDeleted.size
sitesChanged = sitesAdded.size + sitesUpdated.size + sitesDeleted.size
console.log("")
console.log("Rules changed : #{rulesChanged}")
console.log("Trackers changed : #{trackersChanged}")
console.log("Sites changed : #{sitesChanged}")
console.log("")
console.log("Rules added (#{rulesAdded.size}):")
console.log(rulesAdded)
console.log("Ruled updated: #{rulesUpdated.size}")
console.log("Ruled updated (#{rulesUpdated.size}):")
console.log(rulesUpdated)
console.log("Rules deleted: #{rulesDeleted.size}")
console.log("Rules deleted (#{rulesDeleted.size}):")
console.log(rulesDeleted)
console.log("Trackers added: #{trackersAdded.size}")
console.log("")
console.log("Trackers added (#{trackersAdded.size}):")
console.log(trackersAdded)
console.log("Trackers updated: #{trackersUpdated.size}")
console.log("Trackers updated (#{trackersUpdated.size}):")
console.log(trackersUpdated)
console.log("Trackers deleted: #{trackersDeleted.size}")
console.log("Trackers deleted (#{trackersDeleted.size}):")
console.log(trackersDeleted)
console.log("Sites added: #{sitesAdded.size}")
console.log("")
console.log("Sites added (#{sitesAdded.size}):")
console.log(sitesAdded)
console.log("Sites updated: #{sitesUpdated.size}")
console.log("Sites updated (#{sitesUpdated.size}):")
console.log(sitesUpdated)
console.log("Sites deleted: #{sitesDeleted.size}")
console.log("Sites deleted (#{sitesDeleted.size}):")
console.log(sitesDeleted)
console.log("")
# Calculate the last update time based on the content cache.
# Since timestamps have lexographical order, we can use a reduce
......@@ -882,11 +903,25 @@ Better is a Safari content blocker for <a href='https://itunes.apple.com/us/app/
lastModifiedTimes = `Object.values(this.contentCurrentModifiedTimes)`
lastModifiedTime = `lastModifiedTimes.reduce ((x,y) => { return (x > y ? x : y) })`
metadata = JSON.stringify({
metadata = `JSON.stringify({
md5: hash,
lastUpdated: lastModifiedTime
})
lastUpdate: lastModifiedTime,
stats: {
rulesChanged: rulesChanged,
trackersChanged: trackersChanged,
sitesChanged: sitesChanged,
trackers: {
added: [...trackersAdded],
updated: [...trackersUpdated],
deleted: [...trackersDeleted]
},
sites: {
added: [...sitesAdded],
updated: [...sitesUpdated],
deleted: [...sitesDeleted]
}
}
})`
# Save the blocker list file and its metadata.
(fs.outputFileAsync blockerListJSONFilePath, output).then =>
......
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