Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Checksum calculation is lazy and respect use_cache config #220

Merged
merged 1 commit into from

2 participants

@mbacovsky

No description provided.

@iNecas
Owner

Thanks, it seems this might improve the startup time

@iNecas iNecas merged commit 249d1ea into Apipie:master

1 check passed

Details default The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 8 deletions.
  1. +3 −5 README.rst
  2. +12 −3 lib/apipie/application.rb
View
8 README.rst
@@ -908,15 +908,13 @@ And in your apipie initializer allow checksum calculation
Apipie.configuration.update_checksum = true
-and make sure your documentation is loaded.
-
-.. code::
-
- Apipie.reload_documentation
By default the header is added to responses for ``config.doc_base_url`` and ``/api``.
It can be changed in configuration (see `Configuration Reference`_ for details).
+The checksum calculation is lazy, done with first request. If you run with ``use_cache = true``,
+do not forget to run the rake task ``apipie:cache``.
+
===================
Tests Integration
View
15 lib/apipie/application.rb
@@ -266,12 +266,21 @@ def reload_documentation
api_controllers_paths.each do |f|
load_controller_from_file f
end
- @checksum = compute_checksum if Apipie.configuration.update_checksum
+ @checksum = nil if Apipie.configuration.update_checksum
end
def compute_checksum
- all_docs = Apipie.available_versions.inject({}) do |all, version|
- all.update(version => Apipie.to_json(version))
+ if Apipie.configuration.use_cache?
+ file_base = File.join(Apipie.configuration.cache_dir, Apipie.configuration.doc_base_url)
+ all_docs = {}
+ Dir.glob(file_base + '/*.json').sort.each do |f|
+ all_docs[File.basename(f, '.json')] = JSON.parse(File.read(f))
+ end
+ else
+ reload_documentation if available_versions == []
+ all_docs = Apipie.available_versions.inject({}) do |all, version|
+ all.update(version => Apipie.to_json(version))
+ end
end
Digest::MD5.hexdigest(JSON.dump(all_docs))
end
Something went wrong with that request. Please try again.