Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache package meta data during version check #3749

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Paket.Core/Dependencies/NuGet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ let GetTargetsFiles(targetFolder, (pkg : PackageName)) =
[<Obsolete "Use GetContent instead">]
let GetAnalyzerFiles(targetFolder) = getFilesMatching targetFolder "*.dll" "analyzers" "analyzer dlls"

let tryNuGetV3 (auth, nugetV3Url, package:PackageName) =
let tryNuGetV3 (force, auth, nugetV3Url, package:PackageName) =
NuGetV3.findVersionsForPackage(nugetV3Url, auth, package)


Expand Down Expand Up @@ -564,8 +564,8 @@ type GetVersionRequestResult =
member x.Versions =
x.Requests |> Array.collect (fun r -> r.Versions)

let getVersionsCached key f (source, auth, nugetURL, package) =
let request:NuGetCache.NuGetRequestGetVersions = f (auth, nugetURL, package)
let getVersionsCached key f (force, source, auth, nugetURL, package) =
let request:NuGetCache.NuGetRequestGetVersions = f (force, auth, nugetURL, package)
NuGetCache.NuGetRequestGetVersions.ofFunc request.Url (fun _ ->
async {
match protocolCache.TryGetValue(source) with
Expand Down Expand Up @@ -616,16 +616,16 @@ let GetVersions force alternativeProjectRoot root (parameters:GetPackageVersions
| NuGetV2 source ->
let auth = source.Authentication
if String.containsIgnoreCase "artifactory" source.Url then
return [getVersionsCached "ODataNewestFirst" NuGetV2.tryGetAllVersionsFromNugetODataFindByIdNewestFirst (nugetSource, auth, source.Url, packageName) ]
return [ getVersionsCached "ODataNewestFirst" NuGetV2.tryGetAllVersionsFromNugetODataFindByIdNewestFirst (force, nugetSource, auth, source.Url, packageName) ]
else
let v2Feeds =
[ yield getVersionsCached "OData" NuGetV2.tryGetAllVersionsFromNugetODataFindById (nugetSource, auth, source.Url, packageName)
yield getVersionsCached "ODataWithFilter" NuGetV2.tryGetAllVersionsFromNugetODataWithFilter (nugetSource, auth, source.Url, packageName) ]
[ yield getVersionsCached "OData" NuGetV2.tryGetAllVersionsFromNugetODataFindById (force, nugetSource, auth, source.Url, packageName)
yield getVersionsCached "ODataWithFilter" NuGetV2.tryGetAllVersionsFromNugetODataWithFilter (force, nugetSource, auth, source.Url, packageName) ]

return v2Feeds
| NuGetV3 source ->
let! versionsAPI = NuGetV3.getNuGetV3Resource source NuGetV3.AllVersionsAPI
return [ getVersionsCached "V3" tryNuGetV3 (nugetSource, source.Authentication, versionsAPI, packageName) ]
return [ getVersionsCached "V3" tryNuGetV3 (force, nugetSource, source.Authentication, versionsAPI, packageName) ]
| LocalNuGet(path,Some _) ->
return [ NuGetLocal.getAllVersionsFromLocalPath (true, path, packageName, alternativeProjectRoot, root) ]
| LocalNuGet(path,None) ->
Expand Down
46 changes: 24 additions & 22 deletions src/Paket.Core/Dependencies/NuGetCache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -432,44 +432,46 @@ let getCacheDataFromExtractedPackage (packageName:PackageName) (version:SemVerIn
return None
}

let getDetailsFromCacheOr force nugetURL (packageName:PackageName) (version:SemVerInfo) (getViaWebRequest : unit -> ODataSearchResult Async) : ODataSearchResult Async =
let writeCacheFile(result:NuGetPackageCache) =
let cacheFile = getCacheFiles force NuGetPackageCache.CurrentCacheVersion nugetURL packageName version
let serialized = JsonConvert.SerializeObject(result)
let cachedData =
try
if cacheFile.Exists then
use cacheReader = cacheFile.OpenText()
cacheReader.ReadToEnd()
else ""
with
| ex ->
traceWarnfn "Can't read cache file %O:%s Message: %O" cacheFile Environment.NewLine ex
""
if String.CompareOrdinal(serialized, cachedData) <> 0 then
File.WriteAllText(cacheFile.FullName, serialized)
let writePackageDetailsCacheFile force nugetURL (packageName:PackageName) (version:SemVerInfo) (result:NuGetPackageCache) =
let cacheFile = getCacheFiles force NuGetPackageCache.CurrentCacheVersion nugetURL packageName version
let serialized = JsonConvert.SerializeObject(result)
let cachedData =
try
if cacheFile.Exists then
use cacheReader = cacheFile.OpenText()
cacheReader.ReadToEnd()
else ""
with
| ex ->
traceWarnfn "Can't read cache file %O:%s Message: %O" cacheFile Environment.NewLine ex
""
if String.CompareOrdinal(serialized, cachedData) <> 0 then
File.WriteAllText(cacheFile.FullName, serialized)

let getDetailsFromCacheOr force nugetURL (packageName:PackageName) (version:SemVerInfo) (getViaWebRequest : unit -> ODataSearchResult Async) : ODataSearchResult Async =
let getViaWebRequest () =
async {
let! result = getViaWebRequest()
match result with
| Match result ->
writeCacheFile result
writePackageDetailsCacheFile force nugetURL packageName version result
| _ ->
// TODO: Should we cache 404? Probably not.
()
return result
}

async {
match tryGetDetailsFromCache force nugetURL packageName version with
| None when force -> return! getViaWebRequest()
| None when force ->
return! getViaWebRequest()
| None ->
let! result = getCacheDataFromExtractedPackage packageName version
match result with
match! getCacheDataFromExtractedPackage packageName version with
| Some result ->
writeCacheFile result
writePackageDetailsCacheFile force nugetURL packageName version result
return Match result
| _ -> return! getViaWebRequest()
| _ ->
return! getViaWebRequest()
| Some res -> return res
}

Expand Down
Loading