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

Fix compilation page "Force recompile all" button #1759

Merged
merged 1 commit into from
Jan 12, 2024
Merged
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
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);
}
}
Loading