diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 7237be0..6a8a8c0 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -1971 \ No newline at end of file +1972 \ No newline at end of file diff --git a/FLocal.Common/actions/IncrementFieldValue.cs b/FLocal.Common/actions/IncrementFieldValue.cs index 81c7b9b..71c2e0e 100644 --- a/FLocal.Common/actions/IncrementFieldValue.cs +++ b/FLocal.Common/actions/IncrementFieldValue.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Web.Core; namespace FLocal.Common.actions { class IncrementFieldValue : AbstractFieldValue { @@ -37,10 +38,16 @@ namespace FLocal.Common.actions { private readonly Func processor; + private readonly Box resultBox; + public IncrementFieldValue(Func processor) { this.processor = processor; } + public IncrementFieldValue(Func processor, Box resultBox) : this(processor) { + this.resultBox = resultBox; + } + public IncrementFieldValue() : this(INCREMENTOR) { } @@ -48,7 +55,11 @@ namespace FLocal.Common.actions { throw new NotSupportedException(); } public override string getStringRepresentation(string oldInfo) { - return this.processor(oldInfo); + var result = this.processor(oldInfo); + if(this.resultBox != null) { + this.resultBox.value = result; + } + return result; } } diff --git a/FLocal.Common/dataobjects/Thread.cs b/FLocal.Common/dataobjects/Thread.cs index bce218e..a8d2c5a 100644 --- a/FLocal.Common/dataobjects/Thread.cs +++ b/FLocal.Common/dataobjects/Thread.cs @@ -272,7 +272,8 @@ namespace FLocal.Common.dataobjects { }); } - public int getLastReadId(Account account) { + private readonly Dictionary lastReadId_cache = new Dictionary(); + private int do_getLastReadId(Account account) { List stringIds = Config.instance.mainConnection.LoadIdsByConditions( ReadMarkerTableSpec.instance, this.getReadmarkerSearchCondition(account), @@ -282,7 +283,7 @@ namespace FLocal.Common.dataobjects { throw new CriticalException("more than one row"); } if(stringIds.Count < 1) { - return (this.lastPostId >= FORMALREADMIN) ? 0 : this.lastPostId; + return (this.lastPostId >= FORMALREADMIN) ? 0 : FORMALREADMIN; } Dictionary data = Config.instance.mainConnection.LoadById(ReadMarkerTableSpec.instance, stringIds[0]); if((data[ReadMarkerTableSpec.FIELD_POSTID] == "") || (data[ReadMarkerTableSpec.FIELD_POSTID] == null)) { @@ -290,8 +291,28 @@ namespace FLocal.Common.dataobjects { } return int.Parse(data[ReadMarkerTableSpec.FIELD_POSTID]); } + public int getLastReadId(Account account) { + if(!this.lastReadId_cache.ContainsKey(account.id)) { + lock(this.lastReadId_cache) { + if(!this.lastReadId_cache.ContainsKey(account.id)) { + this.lastReadId_cache[account.id] = this.do_getLastReadId(account); + } + } + } + return this.lastReadId_cache[account.id]; + } + private void lastReadId_Reset(Account account, int _lastReadId) { + int lastReadId = _lastReadId; + lock(this.lastReadId_cache) { + if(this.lastReadId_cache.ContainsKey(account.id)) { + lastReadId = Math.Max(lastReadId, _lastReadId); + } + this.lastReadId_cache[account.id] = lastReadId; + } + } public void forceMarkAsRead(Account account, Post maxPost) { + var actualLastRead = new Box(); ChangeSetUtil.ApplyChanges( new InsertOrUpdateChange( ReadMarkerTableSpec.instance, @@ -301,14 +322,18 @@ namespace FLocal.Common.dataobjects { { ReadMarkerTableSpec.FIELD_POSTID, new ScalarFieldValue(maxPost.id.ToString()) }, }, new Dictionary { - { ReadMarkerTableSpec.FIELD_POSTID, new IncrementFieldValue(IncrementFieldValue.GREATEST(maxPost.id)) }, + { ReadMarkerTableSpec.FIELD_POSTID, new IncrementFieldValue(IncrementFieldValue.GREATEST(maxPost.id), actualLastRead) }, }, this.getReadmarkerSearchCondition(account) ) ); + int actualLastReadId = 0; + int.TryParse(actualLastRead.value, out actualLastReadId); + this.lastReadId_Reset(account, actualLastReadId); } public void markAsRead(Account account, Post minPost, Post maxPost) { + Box actualLastRead = new Box(); ChangeSetUtil.ApplyChanges( new InsertOrUpdateChange( ReadMarkerTableSpec.instance, @@ -368,13 +393,17 @@ namespace FLocal.Common.dataobjects { } else { return maxPost.id.ToString(); } - } + }, + actualLastRead ) } }, this.getReadmarkerSearchCondition(account) ) ); + int actualLastReadId = 0; + int.TryParse(actualLastRead.value, out actualLastReadId); + this.lastReadId_Reset(account, actualLastReadId); } internal static KeyValuePair> getNewPostChanges(Board board, int threadId, Post parentPost, User poster, PostLayer layer, string title, string body, DateTime date, int? forcedPostId) { diff --git a/Web.Core/Box.cs b/Web.Core/Box.cs new file mode 100644 index 0000000..b14fe9d --- /dev/null +++ b/Web.Core/Box.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Web.Core { + public class Box { + + public T value; + + } +} diff --git a/Web.Core/Web.Core.csproj b/Web.Core/Web.Core.csproj index 8c5ef31..48fc1b8 100644 --- a/Web.Core/Web.Core.csproj +++ b/Web.Core/Web.Core.csproj @@ -45,6 +45,7 @@ +