Merge pull request #266 from sbwalker/master
infrastructure for dealing with client cache invalidation in a multi-user environment
This commit is contained in:
@ -125,7 +125,7 @@ namespace Oqtane.Modules
|
||||
// logging methods
|
||||
public async Task Log(Alias alias, LogLevel level, string function, Exception exception, string message, params object[] args)
|
||||
{
|
||||
int pageId = PageState.Page.PageId;
|
||||
int pageId = ModuleState.PageId;
|
||||
int moduleId = ModuleState.ModuleId;
|
||||
int? userId = null;
|
||||
if (PageState.User != null)
|
||||
|
@ -39,7 +39,7 @@ namespace Oqtane.Services
|
||||
return await _http.GetJsonAsync<Alias>(apiurl + "/" + AliasId.ToString());
|
||||
}
|
||||
|
||||
public async Task<Alias> GetAliasAsync(string Url)
|
||||
public async Task<Alias> GetAliasAsync(string Url, DateTime LastSyncDate)
|
||||
{
|
||||
Uri uri = new Uri(Url);
|
||||
string name = uri.Authority;
|
||||
@ -51,7 +51,7 @@ namespace Oqtane.Services
|
||||
{
|
||||
name = name.Substring(0, name.Length - 1);
|
||||
}
|
||||
return await _http.GetJsonAsync<Alias>(apiurl + "/name/" + WebUtility.UrlEncode(name));
|
||||
return await _http.GetJsonAsync<Alias>(apiurl + "/name/" + WebUtility.UrlEncode(name) + "?lastsyncdate=" + LastSyncDate.ToString("yyyyMMddHHmmssfff"));
|
||||
}
|
||||
|
||||
public async Task<Alias> AddAliasAsync(Alias alias)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Oqtane.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -10,7 +11,7 @@ namespace Oqtane.Services
|
||||
|
||||
Task<Alias> GetAliasAsync(int AliasId);
|
||||
|
||||
Task<Alias> GetAliasAsync(string Url);
|
||||
Task<Alias> GetAliasAsync(string Url, DateTime LastSyncDate);
|
||||
|
||||
Task<Alias> AddAliasAsync(Alias Alias);
|
||||
|
||||
|
@ -17,5 +17,6 @@ namespace Oqtane.Shared
|
||||
public int ModuleId { get; set; }
|
||||
public string Action { get; set; }
|
||||
public bool EditMode { get; set; }
|
||||
public DateTime LastSyncDate { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -66,16 +66,17 @@
|
||||
|
||||
private async Task Refresh()
|
||||
{
|
||||
Alias alias;
|
||||
Alias alias = null;
|
||||
Site site;
|
||||
List<Page> pages;
|
||||
Page page;
|
||||
User user;
|
||||
User user = null;
|
||||
List<Module> modules;
|
||||
int moduleid = -1;
|
||||
string action = "";
|
||||
bool editmode = false;
|
||||
Reload reload = Reload.None;
|
||||
DateTime lastsyncdate = DateTime.Now;
|
||||
|
||||
// get Url path and querystring ( and remove anchors )
|
||||
string path = new Uri(_absoluteUri).PathAndQuery.Substring(1);
|
||||
@ -99,26 +100,15 @@
|
||||
if (PageState != null)
|
||||
{
|
||||
editmode = PageState.EditMode;
|
||||
lastsyncdate = PageState.LastSyncDate;
|
||||
user = PageState.User;
|
||||
}
|
||||
|
||||
if (PageState == null || reload == Reload.Application)
|
||||
{
|
||||
alias = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
alias = PageState.Alias;
|
||||
}
|
||||
alias = await AliasService.GetAliasAsync(_absoluteUri, lastsyncdate);
|
||||
SiteState.Alias = alias; // set state for services
|
||||
lastsyncdate = alias.SyncDate;
|
||||
|
||||
// check if site has changed
|
||||
Alias current = await AliasService.GetAliasAsync(_absoluteUri);
|
||||
if (alias == null || current.Name != alias.Name)
|
||||
{
|
||||
alias = current;
|
||||
SiteState.Alias = alias; // set state for services
|
||||
reload = Reload.Site;
|
||||
}
|
||||
if (PageState == null || reload <= Reload.Site)
|
||||
if (PageState == null || alias.SiteId != PageState.Alias.SiteId)
|
||||
{
|
||||
site = await SiteService.GetSiteAsync(alias.SiteId, alias);
|
||||
}
|
||||
@ -128,11 +118,34 @@
|
||||
}
|
||||
if (site != null)
|
||||
{
|
||||
// process sync events
|
||||
if (alias.SyncEvents.Any())
|
||||
{
|
||||
if (PageState != null && alias.SyncEvents.Exists(item => item.EntityName == "Page" && item.EntityId == PageState.Page.PageId))
|
||||
{
|
||||
reload = Reload.Page;
|
||||
}
|
||||
if (alias.SyncEvents.Exists(item => item.EntityName == "Site" && item.EntityId == alias.SiteId))
|
||||
{
|
||||
reload = Reload.Site;
|
||||
}
|
||||
if (user != null && alias.SyncEvents.Exists(item => item.EntityName == "User" && item.EntityId == user.UserId))
|
||||
{
|
||||
reload = Reload.Site;
|
||||
}
|
||||
}
|
||||
|
||||
if (PageState == null || reload >= Reload.Site)
|
||||
{
|
||||
#if WASM
|
||||
ModuleDefinitionService.LoadModuleDefinitionsAsync(site.SiteId); // download assemblies to browser when running client-side
|
||||
#endif
|
||||
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
if (authState.User.Identity.IsAuthenticated)
|
||||
{
|
||||
user = await UserService.GetUserAsync(authState.User.Identity.Name, site.SiteId);
|
||||
}
|
||||
pages = await PageService.GetPagesAsync(site.SiteId);
|
||||
}
|
||||
else
|
||||
@ -249,6 +262,7 @@
|
||||
}
|
||||
pagestate.Modules = modules;
|
||||
pagestate.EditMode = editmode;
|
||||
pagestate.LastSyncDate = lastsyncdate;
|
||||
|
||||
OnStateChange?.Invoke(pagestate);
|
||||
}
|
||||
|
Reference in New Issue
Block a user