From 4ecb21c0b00a253478d443d37b1472316c388013 Mon Sep 17 00:00:00 2001 From: Andrew Waage Date: Wed, 18 May 2016 15:40:25 -0700 Subject: [PATCH] first pass at caching. still WIP. Need to parameterize some things --- Gemfile.lock | 16 ++++++++++++++++ github_changelog_generator.gemspec | 2 ++ lib/github_changelog_generator.rb | 3 +++ lib/github_changelog_generator/octo_fetcher.rb | 16 ++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 2c2ff57..86499b2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,12 +4,21 @@ PATH github_changelog_generator (1.13.1) github_api (>= 0.14) rainbow (>= 2.1) + activesupport + faraday-http-cache + github_api (~> 0.12) octokit (~> 4.0) rake (>= 10.0) GEM remote: https://rubygems.org/ specs: + activesupport (4.2.6) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) addressable (2.4.0) ast (2.3.0) childprocess (0.5.9) @@ -28,17 +37,22 @@ GEM docile (1.1.5) faraday (0.9.2) multipart-post (>= 1.2, < 3) + faraday-http-cache (1.3.0) ffi (1.9.14) github_api (0.14.5) + faraday (~> 0.8) addressable (~> 2.4.0) descendants_tracker (~> 0.0.4) faraday (~> 0.8, < 0.10) hashie (>= 3.4) + multi_json (>= 1.7.5, < 2.0) oauth2 (~> 1.0) hashie (3.4.6) + i18n (0.7.0) iniparse (1.4.2) json (1.8.3) jwt (1.5.6) + minitest (5.9.0) multi_json (1.12.1) multi_xml (0.5.5) multipart-post (2.0.0) @@ -92,6 +106,8 @@ GEM thor (0.19.1) thread_safe (0.3.5) tins (1.6.0) + tzinfo (1.2.2) + thread_safe (~> 0.1) unicode-display_width (1.1.1) PLATFORMS diff --git a/github_changelog_generator.gemspec b/github_changelog_generator.gemspec index d6e1f35..cc34887 100644 --- a/github_changelog_generator.gemspec +++ b/github_changelog_generator.gemspec @@ -28,4 +28,6 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "github_api", ">= 0.14" spec.add_runtime_dependency "rainbow", ">= 2.1" spec.add_runtime_dependency("octokit", ["~> 4.0"]) + spec.add_runtime_dependency("faraday-http-cache") + spec.add_runtime_dependency("activesupport") end diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 44b584c..558b451 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -3,6 +3,9 @@ require "github_api" require "octokit" +require 'faraday-http-cache' +require "logger" +require "active_support" require "json" require "benchmark" diff --git a/lib/github_changelog_generator/octo_fetcher.rb b/lib/github_changelog_generator/octo_fetcher.rb index 7b6fa3b..53ec212 100644 --- a/lib/github_changelog_generator/octo_fetcher.rb +++ b/lib/github_changelog_generator/octo_fetcher.rb @@ -27,10 +27,26 @@ module GitHubChangelogGenerator @github_options[:access_token] = @github_token unless @github_token.nil? @github_options[:api_endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil? + init_middleware client_type = @options[:github_endpoint].nil? ? Octokit::Client : Octokit::EnterpriseAdminClient @client = client_type.new(@github_options) end + def init_middleware + middleware_opts = { + :serializer => Marshal, + :store => ActiveSupport::Cache::FileStore.new('/tmp/cache'), + :logger => Logger.new('/tmp/github-changelog-logger.log'), + :shared_cache => false + } + stack = Faraday::RackBuilder.new do |builder| + builder.use Faraday::HttpCache, middleware_opts + builder.use Octokit::Response::RaiseError + builder.adapter Faraday.default_adapter + # builder.response :logger + end + Octokit.middleware = stack + end # Fetch all tags from repo #