|
|
@ -7,6 +7,8 @@ using Web.Core; |
|
|
|
using Web.Core.DB; |
|
|
|
using Web.Core.DB; |
|
|
|
using FLocal.Common; |
|
|
|
using FLocal.Common; |
|
|
|
using FLocal.Common.dataobjects; |
|
|
|
using FLocal.Common.dataobjects; |
|
|
|
|
|
|
|
using System.IO; |
|
|
|
|
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
|
|
|
|
namespace FLocal.IISHandler { |
|
|
|
namespace FLocal.IISHandler { |
|
|
|
class Initializer { |
|
|
|
class Initializer { |
|
|
@ -37,14 +39,20 @@ namespace FLocal.IISHandler { |
|
|
|
|
|
|
|
|
|
|
|
private void DoInitialize() { |
|
|
|
private void DoInitialize() { |
|
|
|
Config.Init(ConfigurationManager.AppSettings); |
|
|
|
Config.Init(ConfigurationManager.AppSettings); |
|
|
|
foreach(var cacher in this.cachers) { |
|
|
|
|
|
|
|
System.Threading.ThreadPool.QueueUserWorkItem(state => this.WrapCacher(cacher)); |
|
|
|
string dir = FLocal.Common.Config.instance.dataDir + "Logs\\"; |
|
|
|
|
|
|
|
using(StreamWriter writer = new StreamWriter(dir + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".INITIALIZE.txt")) { |
|
|
|
|
|
|
|
writer.WriteLine("###INITIALIZE###"); |
|
|
|
|
|
|
|
foreach(var cacher in this.cachers) { |
|
|
|
|
|
|
|
System.Threading.ThreadPool.QueueUserWorkItem(this.GetCacheWrapper(cacher)); |
|
|
|
|
|
|
|
writer.WriteLine("Pending " + cacher.Key); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<Action> cachers { |
|
|
|
private IEnumerable<KeyValuePair<string, Action>> cachers { |
|
|
|
get { |
|
|
|
get { |
|
|
|
yield return this.GetTableCacher<LocalNetwork>(LocalNetwork.LoadByIds, LocalNetwork.TableSpec.instance); |
|
|
|
|
|
|
|
yield return this.GetTableCacher<Machichara>(Machichara.LoadByIds, Machichara.TableSpec.instance); |
|
|
|
yield return this.GetTableCacher<Machichara>(Machichara.LoadByIds, Machichara.TableSpec.instance); |
|
|
|
yield return this.GetTableCacher<ModernSkin>(ModernSkin.LoadByIds, ModernSkin.TableSpec.instance); |
|
|
|
yield return this.GetTableCacher<ModernSkin>(ModernSkin.LoadByIds, ModernSkin.TableSpec.instance); |
|
|
|
yield return this.GetTableCacher<PostLayer>(PostLayer.LoadByIds, PostLayer.TableSpec.instance); |
|
|
|
yield return this.GetTableCacher<PostLayer>(PostLayer.LoadByIds, PostLayer.TableSpec.instance); |
|
|
@ -52,37 +60,71 @@ namespace FLocal.IISHandler { |
|
|
|
yield return this.GetTableCacher<QuickLink>(QuickLink.LoadByIds, QuickLink.TableSpec.instance); |
|
|
|
yield return this.GetTableCacher<QuickLink>(QuickLink.LoadByIds, QuickLink.TableSpec.instance); |
|
|
|
yield return this.GetTableCacher<Skin>(Skin.LoadByIds, Skin.TableSpec.instance); |
|
|
|
yield return this.GetTableCacher<Skin>(Skin.LoadByIds, Skin.TableSpec.instance); |
|
|
|
yield return this.GetTableCacher<UserGroup>(UserGroup.LoadByIds, UserGroup.TableSpec.instance); |
|
|
|
yield return this.GetTableCacher<UserGroup>(UserGroup.LoadByIds, UserGroup.TableSpec.instance); |
|
|
|
yield return this.CacheCategories; |
|
|
|
yield return new KeyValuePair<string, Action>("categories", this.CacheCategories); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void WrapCacher(Action cacher) { |
|
|
|
private WaitCallback GetCacheWrapper(KeyValuePair<string, Action> cacher) { |
|
|
|
try { |
|
|
|
return state => { |
|
|
|
cacher(); |
|
|
|
string dir = FLocal.Common.Config.instance.dataDir + "Logs\\"; |
|
|
|
} catch(FLocalException) { |
|
|
|
|
|
|
|
} |
|
|
|
DateTime start = DateTime.Now; |
|
|
|
|
|
|
|
/*using(StreamWriter writer = new StreamWriter(dir + start.ToString("yyyy-MM-dd_HH-mm-ss") + ".init." + cacher.Key + ".txt")) { |
|
|
|
|
|
|
|
writer.WriteLine("###INITIALIZER/CACHER###"); |
|
|
|
|
|
|
|
writer.WriteLine("info: " + cacher.Value.Method.Name); |
|
|
|
|
|
|
|
writer.WriteLine(); |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FLocalException error = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
cacher.Value(); |
|
|
|
|
|
|
|
} catch(FLocalException e) { |
|
|
|
|
|
|
|
error = e; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateTime end = DateTime.Now; |
|
|
|
|
|
|
|
using(StreamWriter writer = new StreamWriter(dir + end.ToString("yyyy-MM-dd_HH-mm-ss") + ".initend." + cacher.Key + ".txt")) { |
|
|
|
|
|
|
|
writer.WriteLine("###INITIALIZER/CACHER###"); |
|
|
|
|
|
|
|
writer.WriteLine("info: " + cacher.Value.Method.Name); |
|
|
|
|
|
|
|
writer.WriteLine("Start: " + start); |
|
|
|
|
|
|
|
writer.WriteLine(); |
|
|
|
|
|
|
|
if(error != null) { |
|
|
|
|
|
|
|
writer.WriteLine("Exception: " + error.GetType().FullName); |
|
|
|
|
|
|
|
writer.WriteLine("Guid: " + error.GetGuid().ToString()); |
|
|
|
|
|
|
|
writer.WriteLine(error.Message); |
|
|
|
|
|
|
|
if(error is FLocalException) { |
|
|
|
|
|
|
|
writer.WriteLine(((FLocalException)error).FullStackTrace); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
writer.WriteLine(error.StackTrace); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Action GetTableCacher<SqlObjectType>(Func<IEnumerable<int>, List<SqlObjectType>> objectsLoader, ITableSpec tableSpec) |
|
|
|
private KeyValuePair<string, Action> GetTableCacher<SqlObjectType>(Func<IEnumerable<int>, List<SqlObjectType>> objectsLoader, ITableSpec tableSpec) |
|
|
|
where SqlObjectType : SqlObject<SqlObjectType>, new() |
|
|
|
where SqlObjectType : SqlObject<SqlObjectType>, new() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return () => { |
|
|
|
return new KeyValuePair<string,Action>( |
|
|
|
foreach( |
|
|
|
typeof(SqlObjectType).FullName, |
|
|
|
SqlObjectType sqlObject |
|
|
|
() => { |
|
|
|
in |
|
|
|
foreach( |
|
|
|
objectsLoader( |
|
|
|
SqlObjectType sqlObject |
|
|
|
from stringId |
|
|
|
in |
|
|
|
in Config.instance.mainConnection.LoadIdsByConditions( |
|
|
|
objectsLoader( |
|
|
|
tableSpec, |
|
|
|
from stringId |
|
|
|
new Web.Core.DB.conditions.EmptyCondition(), |
|
|
|
in Config.instance.mainConnection.LoadIdsByConditions( |
|
|
|
Diapasone.unlimited |
|
|
|
tableSpec, |
|
|
|
|
|
|
|
new Web.Core.DB.conditions.EmptyCondition(), |
|
|
|
|
|
|
|
Diapasone.unlimited |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
select int.Parse(stringId) |
|
|
|
) |
|
|
|
) |
|
|
|
select int.Parse(stringId) |
|
|
|
) { |
|
|
|
) |
|
|
|
sqlObject.LoadIfNotLoaded(); |
|
|
|
) { |
|
|
|
} |
|
|
|
sqlObject.LoadIfNotLoaded(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void CacheCategories() { |
|
|
|
private void CacheCategories() { |
|
|
@ -101,10 +143,10 @@ namespace FLocal.IISHandler { |
|
|
|
|
|
|
|
|
|
|
|
if(_maxPostId.HasValue) { |
|
|
|
if(_maxPostId.HasValue) { |
|
|
|
int maxPostId = _maxPostId.Value; |
|
|
|
int maxPostId = _maxPostId.Value; |
|
|
|
int minPostId = Math.Min(maxPostId - 10000, 0); |
|
|
|
int minPostId = Math.Max(maxPostId - 10000, 0); |
|
|
|
for(int i=maxPostId; i>minPostId; i++) { |
|
|
|
for(int i=maxPostId; i>minPostId; i--) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
var post = Post.LoadById(i); |
|
|
|
CachePost(Post.LoadById(i)); |
|
|
|
} catch(NotFoundInDBException) { |
|
|
|
} catch(NotFoundInDBException) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -116,9 +158,18 @@ namespace FLocal.IISHandler { |
|
|
|
post.LoadIfNotLoaded(); |
|
|
|
post.LoadIfNotLoaded(); |
|
|
|
post.thread.LoadIfNotLoaded(); |
|
|
|
post.thread.LoadIfNotLoaded(); |
|
|
|
post.poster.LoadIfNotLoaded(); |
|
|
|
post.poster.LoadIfNotLoaded(); |
|
|
|
post.latestRevision.LoadIfNotLoaded(); |
|
|
|
if(post.poster.avatarId != null) { |
|
|
|
post.parentPost.LoadIfNotLoaded(); |
|
|
|
post.poster.avatar.LoadIfNotLoaded(); |
|
|
|
post.parentPost.latestRevision.LoadIfNotLoaded(); |
|
|
|
} |
|
|
|
|
|
|
|
if(post.revision != null) { |
|
|
|
|
|
|
|
post.latestRevision.LoadIfNotLoaded(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(post.parentPostId != null) { |
|
|
|
|
|
|
|
post.parentPost.LoadIfNotLoaded(); |
|
|
|
|
|
|
|
if(post.parentPost.revision != null) { |
|
|
|
|
|
|
|
post.parentPost.latestRevision.LoadIfNotLoaded(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
foreach(var punishment in post.punishments) { |
|
|
|
foreach(var punishment in post.punishments) { |
|
|
|
punishment.LoadIfNotLoaded(); |
|
|
|
punishment.LoadIfNotLoaded(); |
|
|
|
punishment.moderator.LoadIfNotLoaded(); |
|
|
|
punishment.moderator.LoadIfNotLoaded(); |
|
|
|