Skip to content

Commit

Permalink
Cache which source contains versions in GetVersions - references #1320
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Dec 23, 2015
1 parent 0278177 commit 01f5dbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### 2.39.0 - 23.12.2015
#### 2.39.1 - 23.12.2015
* PERFORMANCE: Cache which source contains versions in GetVersions - https://github.com/fsprojects/Paket/pull/1327

#### 2.38.0 - 22.12.2015
Expand Down
20 changes: 13 additions & 7 deletions src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -529,18 +529,24 @@ let getVersionsCached key f (source, auth, nugetURL, package) =

/// Allows to retrieve all version no. for a package from the given sources.
let GetVersions force root (sources, packageName:PackageName) =
let sources = sources |> Array.ofSeq

let getVersionsFailedCacheFileName (source:PackageSource) =
let h = source.Url |> normalizeUrl |> hash |> abs
let packageUrl = sprintf "Versions.%O.s%d.failed" packageName h
FileInfo(Path.Combine(CacheFolder,packageUrl))

let sources =
sources
|> Array.ofSeq
|> Array.map (fun nugetSource ->
let errorFile = getVersionsFailedCacheFileName nugetSource
errorFile.Exists,nugetSource)

let force = force || Array.forall fst sources

let versionResponse =
sources
|> Seq.map (fun nugetSource ->
let errorFile = getVersionsFailedCacheFileName nugetSource
if (not force) && errorFile.Exists then [] else
|> Seq.map (fun (errorFileExists,nugetSource) ->
if (not force) && errorFileExists then [] else
match nugetSource with
| NuGetV2 source ->
let auth = source.Authentication |> Option.map toBasicAuth
Expand Down Expand Up @@ -575,7 +581,7 @@ let GetVersions force root (sources, packageName:PackageName) =
let mergedVersions =
versionResponse
|> Array.zip sources
|> Array.choose (fun (s,v) ->
|> Array.choose (fun ((_,s),v) ->
match v with
| Some v when Array.isEmpty v |> not -> Some (s,v)
| _ ->
Expand All @@ -592,7 +598,7 @@ let GetVersions force root (sources, packageName:PackageName) =
match mergedVersions with
| versions when Array.isEmpty versions |> not -> versions
| _ ->
match sources |> Seq.map (fun (s:PackageSource) -> s.ToString()) |> List.ofSeq with
match sources |> Seq.map (fun (_,s:PackageSource) -> s.ToString()) |> List.ofSeq with
| [source] ->
failwithf "Could not find versions for package %O on %O." packageName source
| [] ->
Expand Down

0 comments on commit 01f5dbe

Please sign in to comment.