Skip to content

Commit

Permalink
Backend: cache events and contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
harding committed Sep 7, 2015
1 parent 90dc6a0 commit b3f4ba5
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@ ehthumbs.db
Thumbs.db
.bundle
vendor
_cache
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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
Expand Down
41 changes: 38 additions & 3 deletions _plugins/contributors.rb
Expand Up @@ -106,9 +106,44 @@ def site_payload
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

Expand Down
55 changes: 52 additions & 3 deletions _plugins/events.rb
Expand Up @@ -142,9 +142,58 @@ def site_payload
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
Expand Down

0 comments on commit b3f4ba5

Please sign in to comment.