Skip to content

Commit

Permalink
Merge pull request #495 from fsprojects/perf
Browse files Browse the repository at this point in the history
Caching should parse the JSON correctly - primary ctor was missing
  • Loading branch information
forki committed Dec 31, 2014
2 parents 400a75f + e14c8cf commit ad9c054
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Paket.Core/Domain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// Represents a NuGet package name
[<System.Diagnostics.DebuggerDisplay("{Item}")>]
type PackageName =
private | PackageName of string
| PackageName of string

member this.Id =
match this with
Expand All @@ -18,7 +18,7 @@ let PackageName name = PackageName.PackageName name
/// Represents a normalized NuGet package name
[<System.Diagnostics.DebuggerDisplay("{Item}")>]
type NormalizedPackageName =
private | NormalizedPackageName of string
| NormalizedPackageName of string

/// Active recognizer to convert a NuGet package name into a normalized one
let (|NormalizedPackageName|) (PackageName name) =
Expand Down
12 changes: 9 additions & 3 deletions src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ let CacheFolder =
di.Create()
di.FullName

let inline normalizeUrl(url:string) = url.Replace("https","http").Replace("www.","")

let private loadFromCacheOrOData force fileName auth nugetURL package version =
async {
if not force && File.Exists fileName then
Expand All @@ -238,9 +240,12 @@ let private loadFromCacheOrOData force fileName auth nugetURL package version =
let getDetailsFromNuget force auth nugetURL package (version:SemVerInfo) =
async {
try
let fi = FileInfo(Path.Combine(CacheFolder,sprintf "%s.%s.json" package (version.Normalize())))
let fi =
let packageUrl = sprintf "%s.%s.json" package (version.Normalize())
FileInfo(Path.Combine(CacheFolder,packageUrl))

let! (invalidCache,details) = loadFromCacheOrOData force fi.FullName auth nugetURL package version
if details.SourceUrl <> nugetURL then
if normalizeUrl details.SourceUrl <> normalizeUrl nugetURL then
return! getDetailsFromNuGetViaOData auth nugetURL package version
else
if invalidCache then
Expand Down Expand Up @@ -420,7 +425,8 @@ let GetPackageDetails force sources (PackageName package) (version:SemVerInfo) :
version
|> Async.RunSynchronously
| LocalNuget path ->
getDetailsFromLocalFile path package version |> Async.RunSynchronously
getDetailsFromLocalFile path package version
|> Async.RunSynchronously
|> fun x -> source,x
with _ -> tryNext rest
| [] -> failwithf "Couldn't get package details for package %s on %A." package (sources |> List.map (fun (s:PackageSource) -> s.ToString()))
Expand Down

0 comments on commit ad9c054

Please sign in to comment.