Skip to content

Commit

Permalink
Force initialize tree after startup. Closes #274.
Browse files Browse the repository at this point in the history
  • Loading branch information
impworks committed Jan 28, 2024
1 parent b2fa957 commit eb47bba
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Bonsai/Code/Config/Startup.Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Bonsai.Areas.Admin.Logic.Tree;
using Bonsai.Code.Services;
using Bonsai.Code.Services.Config;
using Bonsai.Code.Services.Jobs;
using Bonsai.Code.Services.Search;
using Bonsai.Data;
using Bonsai.Data.Models;
Expand Down Expand Up @@ -134,14 +136,29 @@ private void InitDatabase(IApplicationBuilder app)
var pages = await db.Pages.Include(x => x.Aliases).ToListAsync();
foreach (var page in pages)
await search.AddPageAsync(page);
});
}
);

startupService.AddTask(
"BuildPageReferences",
"Обнаружение ссылок между страницами",
() => BuildPageReferences(sp)
);

startupService.AddTask(
"InitTree",
"Построение дерева",
async () =>
{
var db = sp.GetService<AppDbContext>();
if (await db.TreeLayouts.AnyAsync())
return;

var jobs = sp.GetService<IBackgroundJobService>();
await jobs.RunAsync(JobBuilder.For<TreeLayoutJob>().SupersedeAll());
}
);

startupService.AddTask("CheckMissingMedia", "", () => CheckMissingMediaAsync(sp));

startupService.AddTask("Finalize", "", async () => scope.Dispose());
Expand All @@ -157,7 +174,7 @@ private async Task CheckMissingMediaAsync(IServiceProvider sp)
var db = sp.GetService<AppDbContext>();
var env = sp.GetService<IWebHostEnvironment>();

if (!(await db.Media.AnyAsync()))
if (await db.Media.AnyAsync() == false)
return;

var path = Path.Combine(env.WebRootPath, "media");
Expand Down

0 comments on commit eb47bba

Please sign in to comment.