[smuxi] Engine: implemented truncation of SqliteMessageBuffer



commit 68932273c0a18cf1c1fd1aa1f8d255b2d401eb24
Author: Mirco Bauer <meebey meebey net>
Date:   Wed Feb 26 23:51:31 2014 +0100

    Engine: implemented truncation of SqliteMessageBuffer

 src/Engine/MessageBuffers/SqliteMessageBuffer.cs |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/src/Engine/MessageBuffers/SqliteMessageBuffer.cs 
b/src/Engine/MessageBuffers/SqliteMessageBuffer.cs
index 97f574d..bb3f89e 100644
--- a/src/Engine/MessageBuffers/SqliteMessageBuffer.cs
+++ b/src/Engine/MessageBuffers/SqliteMessageBuffer.cs
@@ -35,6 +35,7 @@ namespace Smuxi.Engine
 #endif
         string DBPath { get; set; }
         SqliteConnection Connection { get; set; }
+        Int64 MessageCount { get; set; }
 
         public override int Count {
             get {
@@ -73,6 +74,8 @@ namespace Smuxi.Engine
                 cmd.CommandText = sql;
                 cmd.ExecuteNonQuery();
             }
+
+            MessageCount = Count;
         }
 
         public override void Add(MessageModel msg)
@@ -81,6 +84,10 @@ namespace Smuxi.Engine
                 throw new ArgumentNullException("msg");
             }
 
+            if (MaxCapacity > 0 && MessageCount >= MaxCapacity) {
+                RemoveAt(0);
+            }
+
             var dto = new MessageDtoModelV1(msg);
             var json = JsonSerializer.SerializeToString(dto);
 
@@ -94,6 +101,7 @@ namespace Smuxi.Engine
 
                 cmd.ExecuteNonQuery();
             }
+            MessageCount++;
         }
 
         public override IList<MessageModel> GetRange(int offset, int limit)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]