Skip to content

Commit

Permalink
Fix memoization for get-dependencies. Fixes technomancy#1781.
Browse files Browse the repository at this point in the history
This should speed things up a lot!
  • Loading branch information
technomancy committed May 30, 2017
1 parent 5f0b0a1 commit ad6c4bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 2.8.0 / ???

* Fix a bug where dependency resolution wasn't cached correctly. (Phil Hagelberg)
* Warn when `$CLASSPATH` is set. (Phil Hagelberg)
* Remove warning when running as root. (Phil Hagelberg)
* Add `why` subtask to `deps` for tracing individual deps. (Phil Hagelberg)
* Remove clj-http and cheshire dependencies, reducing likelihood of conflict (Phil Hagelberg)
* Warn when plugin dependencies conflict with Leiningen's own. (Phil Hagelberg)
Expand Down
21 changes: 12 additions & 9 deletions leiningen-core/src/leiningen/core/classpath.clj
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,22 @@
(defn- root-cause [e]
(last (take-while identity (iterate (memfn getCause) e))))

(def ^:private ^:dynamic *dependencies-session*
"This is dynamic in order to avoid memoization issues.")

(def ^:private get-dependencies-memoized
(memoize
(fn [dependencies-key managed-dependencies-key
{:keys [repositories local-repo offline? update
checksum mirrors] :as project}
{:keys [add-classpath? repository-session-fn] :as args}]
{:keys [add-classpath?] :as args}]
{:pre [(every? vector? (get project dependencies-key))
(every? vector? (get project managed-dependencies-key))]}
(try
((if add-classpath?
pomegranate/add-dependencies
aether/resolve-dependencies)
:repository-session-fn repository-session-fn
:repository-session-fn *dependencies-session*
:local-repo local-repo
:offline? offline?
:repositories (->> repositories
Expand Down Expand Up @@ -310,14 +313,14 @@
(defn ^:internal get-dependencies [dependencies-key managed-dependencies-key
project & args]
(let [ranges (atom []), overrides (atom [])
session (pedantic/session project ranges overrides)
args (assoc (apply hash-map args) :repository-session-fn session)
trimmed (select-keys project [dependencies-key managed-dependencies-key
:repositories :checksum :local-repo :offline?
:update :mirrors])
deps-result (get-dependencies-memoized dependencies-key
managed-dependencies-key
trimmed args)]
:repositories :checksum :local-repo
:offline? :update :mirrors])
deps-result (binding [*dependencies-session* (pedantic/session
project ranges overrides)]
(get-dependencies-memoized dependencies-key
managed-dependencies-key
trimmed (apply hash-map args)))]
(pedantic/do (:pedantic? project) @ranges @overrides)
deps-result))

Expand Down

0 comments on commit ad6c4bd

Please sign in to comment.