Skip to content

Commit

Permalink
Fix compilation page "Force recompile all" button
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Jan 31, 2024
1 parent da7b62b commit bba65af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ void editCompilationException(DotvvmCompilationException ex)
}
}

/// <summary> Removes an old entry from the cache, forcing a recompilation. If loading of this view is already running </summary>
public void InvalidateCache(string virtualPath)
{
this.markupFiles.TryRemove(virtualPath, out _);
this.controlBuilders.TryRemove(virtualPath, out _);
}

public void LoadCompiledViewsAssembly(string filePath)
{
var assembly = TryFindAssembly(filePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand Down Expand Up @@ -105,10 +105,11 @@ public async Task<bool> CompileAll(bool buildInParallel = true, bool forceRecomp
var discoveredMasterPages = new ConcurrentDictionary<string, DotHtmlFileInfo>();


Func<DotHtmlFileInfo, Action> compilationTaskFactory = t => new Action(() => {
BuildView(t, out var masterPage);
if (masterPage != null && masterPage.Status == CompilationState.None) discoveredMasterPages.TryAdd(masterPage.VirtualPath, masterPage);
});
var compilationTaskFactory = (DotHtmlFileInfo t) => () => {
BuildView(t, forceRecompile, out var masterPage);
if (masterPage != null && masterPage.Status == CompilationState.None)
discoveredMasterPages.TryAdd(masterPage.VirtualPath, masterPage);
};

var compileTasks = filesToCompile.Select(compilationTaskFactory).ToArray();
await ExecuteCompileTasks(compileTasks, buildInParallel);
Expand Down Expand Up @@ -144,13 +145,19 @@ private async Task ExecuteCompileTasks(Action[] compileTasks, bool buildInParall
}
}

public bool BuildView(DotHtmlFileInfo file, out DotHtmlFileInfo? masterPage)
public bool BuildView(DotHtmlFileInfo file, out DotHtmlFileInfo? masterPage) =>
BuildView(file, false, out masterPage);
public bool BuildView(DotHtmlFileInfo file, bool forceRecompile, out DotHtmlFileInfo? masterPage)
{
masterPage = null;
if (file.Status != CompilationState.NonCompilable)
{
try
{
if (forceRecompile)
// TODO: next major version - add method to interface
(controlBuilderFactory as DefaultControlBuilderFactory)?.InvalidateCache(file.VirtualPath);

var pageBuilder = controlBuilderFactory.GetControlBuilder(file.VirtualPath);

using var scopedServiceProvider = dotvvmConfiguration.ServiceProvider.CreateScope(); // dependencies that are configured as scoped cannot be resolved from root service provider
Expand Down
2 changes: 2 additions & 0 deletions src/Framework/Framework/Compilation/IControlBuilderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ namespace DotVVM.Framework.Compilation
public interface IControlBuilderFactory
{
(ControlBuilderDescriptor descriptor, Lazy<IControlBuilder> builder) GetControlBuilder(string virtualPath);
// TODO: next major version
// void InvalidateCache(string virtualPath);
}
}

0 comments on commit bba65af

Please sign in to comment.