Backend: cache events and contributors

This commit is contained in:
David A. Harding 2015-09-06 18:21:19 -04:00
parent 90dc6a02b6
commit b3f4ba58f8
No known key found for this signature in database
GPG key ID: 4B29C30FF29EC4B7
4 changed files with 92 additions and 7 deletions

1
.gitignore vendored
View file

@ -9,3 +9,4 @@ ehthumbs.db
Thumbs.db
.bundle
vendor
_cache

View file

@ -102,7 +102,7 @@ build:
| egrep -v 'sha256sums.txt' \
| sort \
| xargs -d '\n' sha256sum > _site/sha256sums.txt
$S git show --oneline > _site/commit.txt
$S git log -1 --format="%H" > _site/commit.txt
## Jekyll annoyingly returns success even when it emits errors and
## exceptions, so we'll grep its output for error strings

View file

@ -106,9 +106,44 @@ module Jekyll
return
end
# Populate site.corecontributors and site.sitecontributors arrays
site.corecontributors = contributors('bitcoin/bitcoin',site.config['aliases'])
site.sitecontributors = contributors('bitcoin-dot-org/bitcoin.org',site.config['aliases'])
## Create cache directory if it doesn't exist
if !File.exists?('_cache')
Dir.mkdir('_cache')
end
# Populate site.corecontributors and site.sitecontributors with
# data from GitHub.com. Store data in the cache and only
# re-retrieve the data if 86,400 seconds (24 hours) passes from
# the retrieval date or if the cache file is deleted. For
# simplicity, updates on the two cache files are linked, so if one
# file has to be updated, they both get updated.
corecontributors_cache = '_cache/corecontributors.marshall'
sitecontributors_cache = '_cache/sitecontributors.marshall'
if File.exists?(corecontributors_cache) && File.exists?(sitecontributors_cache)
corecontributors_cache_age = (Time.now - File.stat(corecontributors_cache).mtime).to_i
sitecontributors_cache_age = (Time.now - File.stat(sitecontributors_cache).mtime).to_i
else
corecontributors_cache_age = Time.now.to_i
sitecontributors_cache_age = Time.now.to_i
end
if corecontributors_cache_age > 86400 || sitecontributors_cache_age > 86400
site.corecontributors = contributors('bitcoin/bitcoin',site.config['aliases'])
File.open(corecontributors_cache,'w') do |file|
Marshal.dump(site.corecontributors, file)
end
site.sitecontributors = contributors('bitcoin-dot-org/bitcoin.org',site.config['aliases'])
File.open(sitecontributors_cache,'w') do |file|
Marshal.dump(site.sitecontributors, file)
end
else
File.open(corecontributors_cache,'r') do |file|
site.corecontributors = Marshal.load(file)
end
File.open(sitecontributors_cache,'r') do |file|
site.sitecontributors = Marshal.load(file)
end
end
end

View file

@ -142,9 +142,58 @@ module Jekyll
return
end
# Populate site.conferences and site.meetups arrays
site.conferences = conferences()
site.meetups = meetups()
## Create cache directory if it doesn't exist
if !File.exists?('_cache')
Dir.mkdir('_cache')
end
## Populate site.conferences with conferences from _events.yml
## plus geodata from Google. Store data in the cache and only
## re-retrieve the geodata if _events.yml is edited or the cache
## file is deleted.
conferences_cache = '_cache/conferences.marshall'
events_file = '_events.yml'
events_file_unix_time = File.stat(events_file).mtime.to_i
if File.exists?(conferences_cache)
conferences_cache_unix_time = File.stat(conferences_cache).mtime.to_i
else
conferences_cache_unix_time = 0
end
if events_file_unix_time >= conferences_cache_unix_time
site.conferences = conferences()
File.open(conferences_cache,'w') do |file|
Marshal.dump(site.conferences, file)
end
else
File.open(conferences_cache,'r') do |file|
site.conferences = Marshal.load(file)
end
end
# Populate site.meetups with data from Meetup.com. Store data in
# the cache and only re-retrieve the data if 86,400 seconds (24
# hours) passes from the retrieval date or if the cache file is
# deleted.
meetups_cache = '_cache/meetups.marshall'
if File.exists?(meetups_cache)
meetups_cache_age = (Time.now - File.stat(meetups_cache).mtime).to_i
else
meetups_cache_age = Time.now.to_i
end
if meetups_cache_age > 86400
site.meetups = meetups()
File.open(meetups_cache,'w') do |file|
Marshal.dump(site.meetups, file)
end
else
File.open(meetups_cache,'r') do |file|
site.meetups = Marshal.load(file)
end
end
end
end