From c30f110e4c907221eb7609c95aeb7bbc7f9c1038 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Thu, 11 Jun 2020 00:08:03 +0200 Subject: [PATCH] Avoid recomputing the readme for module rules --- src/Review/Rule.elm | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/Review/Rule.elm b/src/Review/Rule.elm index 2d34b6ba..96bd83d3 100644 --- a/src/Review/Rule.elm +++ b/src/Review/Rule.elm @@ -579,6 +579,7 @@ reverseVisitors (ModuleRuleSchema schema) = type alias ModuleRuleCache moduleContext = { initialContext : moduleContext , elmJson : SimpleCacheEntryFor (Maybe Elm.Project.Project) moduleContext + , readme : SimpleCacheEntryFor (Maybe String) moduleContext , moduleResults : ModuleRuleResultCache } @@ -599,20 +600,20 @@ type alias ModuleRuleResultCache = runModuleRule : ModuleRuleSchema { schemaState | hasAtLeastOneVisitor : () } moduleContext -> Maybe (ModuleRuleCache moduleContext) -> Exceptions -> Project -> List (Graph.NodeContext ModuleName ()) -> ( List (Error {}), Rule ) runModuleRule ((ModuleRuleSchema schema) as moduleRuleSchema) maybePreviousCache exceptions project _ = let - elmJson : Maybe Elm.Project.Project - elmJson = - Review.Project.elmJson project - |> Maybe.map .project - elmJsonCacheEntry : SimpleCacheEntryFor (Maybe Elm.Project.Project) moduleContext elmJsonCacheEntry = let + elmJson : Maybe Elm.Project.Project + elmJson = + Review.Project.elmJson project + |> Maybe.map .project + computeElmJson : () -> SimpleCacheEntryFor (Maybe Elm.Project.Project) moduleContext computeElmJson () = { value = elmJson , context = schema.initialContext - |> accumulateContext schema.elmJsonVisitors (Review.Project.elmJson project |> Maybe.map .project) + |> accumulateContext schema.elmJsonVisitors elmJson } in case maybePreviousCache of @@ -626,10 +627,35 @@ runModuleRule ((ModuleRuleSchema schema) as moduleRuleSchema) maybePreviousCache Nothing -> computeElmJson () + readmeCacheEntry : SimpleCacheEntryFor (Maybe String) moduleContext + readmeCacheEntry = + let + readme : Maybe String + readme = + Review.Project.readme project |> Maybe.map .content + + computeReadme : () -> SimpleCacheEntryFor (Maybe String) moduleContext + computeReadme () = + { value = readme + , context = + elmJsonCacheEntry.context + |> accumulateContext schema.readmeVisitors readme + } + in + case maybePreviousCache of + Just previousCache -> + if previousCache.readme.value == readme && elmJsonCacheEntry.context == previousCache.elmJson.context then + previousCache.readme + + else + computeReadme () + + Nothing -> + computeReadme () + initialContext : moduleContext initialContext = - elmJsonCacheEntry.context - |> accumulateContext schema.readmeVisitors (Review.Project.readme project |> Maybe.map .content) + readmeCacheEntry.context |> accumulateContext schema.dependenciesVisitors (Review.Project.dependencies project) newCache : ModuleRuleCache moduleContext @@ -642,12 +668,14 @@ runModuleRule ((ModuleRuleSchema schema) as moduleRuleSchema) maybePreviousCache else { initialContext = initialContext , elmJson = elmJsonCacheEntry + , readme = readmeCacheEntry , moduleResults = Dict.empty } Nothing -> { initialContext = initialContext , elmJson = elmJsonCacheEntry + , readme = readmeCacheEntry , moduleResults = Dict.empty } @@ -692,6 +720,7 @@ runModuleRule ((ModuleRuleSchema schema) as moduleRuleSchema) maybePreviousCache (Just { initialContext = newCache.initialContext , elmJson = elmJsonCacheEntry + , readme = readmeCacheEntry , moduleResults = moduleResults } )