Skip to content

Commit 3b7a7c5

Browse files
Add database installation check in GetDatabaseVersion
1 parent 38e5366 commit 3b7a7c5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Web/Grand.Web.Common/Middleware/InstallUrlMiddleware.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public InstallUrlMiddleware(RequestDelegate next, ICacheBase cacheBase)
3939
public async Task InvokeAsync(HttpContext context)
4040
{
4141
var databaseIsInstalled = DataSettingsManager.DatabaseIsInstalled();
42-
var version = GetDatabaseVersion(context);
42+
var version = GetDatabaseVersion(context, databaseIsInstalled);
4343

4444
if (version == null)
4545
{
@@ -69,12 +69,14 @@ await context.Response.WriteAsync("The database version is not supported in this
6969
//call the next middleware in the request pipeline
7070
await _next(context);
7171
}
72-
private GrandNodeVersion? GetDatabaseVersion(HttpContext context)
72+
private GrandNodeVersion? GetDatabaseVersion(HttpContext context, bool databaseIsInstalled)
7373
{
7474
return _cacheBase.Get(CacheKey.GRAND_NODE_VERSION, () =>
7575
{
76-
var repository = context.RequestServices.GetRequiredService<IRepository<GrandNodeVersion>>();
77-
return repository.Table.FirstOrDefault();
76+
if (databaseIsInstalled)
77+
return context.RequestServices.GetRequiredService<IRepository<GrandNodeVersion>>().Table.FirstOrDefault();
78+
79+
return null;
7880
}, int.MaxValue);
7981
}
8082

0 commit comments

Comments
 (0)