summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Ostler <scottbot9000@gmail.com>2010-06-14 17:17:48 -0400
committerScott Ostler <scottbot9000@gmail.com>2010-06-14 17:17:48 -0400
commit91430f25eea4da648ee84b2aebe498670baa949b (patch)
tree01845d7f6d68f863452f6063b4057aebc9e2f904 /src
parente253b6fa840296c81a1aa71970a82e9d73257150 (diff)
Truncate message list
Diffstat (limited to 'src')
-rw-r--r--src/rooms.clj9
-rwxr-xr-xsrc/utils.clj10
2 files changed, 15 insertions, 4 deletions
diff --git a/src/rooms.clj b/src/rooms.clj
index c1b596b..a7fe933 100644
--- a/src/rooms.clj
+++ b/src/rooms.clj
@@ -91,13 +91,16 @@
(alter (room :users) assoc (user :nick) user))
; Note: To ensure that the msg's timestamp is consistent
-; with other msg creations, build-msg should be called
-; from within a dosync.
+; with other msg creations, build-msg should be used
+; within a dosync.
(defn build-msg [nick content msg-id]
(struct message-struct nick content (new Date) msg-id))
+
+(def message-count-limit 200)
+
(defn add-message [msg room]
- (alter (room :messages) (swap cons) msg))
+ (insert-and-truncate! (room :messages) msg message-count-limit))
(defn insert-message-into-db! [user-id room-id content is-image]
(:message_id
diff --git a/src/utils.clj b/src/utils.clj
index 3f1a7b1..779bb7b 100755
--- a/src/utils.clj
+++ b/src/utils.clj
@@ -25,7 +25,7 @@
(.setDatabaseName db-name)
(.setUser db-user)
(.setPassword db-pass)
- (.setMaxConnections 3))}))
+ (.setMaxConnections 20))}))
;; moved this to here which doesn't seem right... maybe a 'settings.clj' or something?
(def *dumps-per-page* 20)
@@ -98,6 +98,14 @@
[(int (/ (- f# s#) 1e6)) r#]))
+(def truncation-factor 2)
+
+(defn insert-and-truncate! [list-ref item soft-limit]
+ (if (> (count @list-ref) (* soft-limit truncation-factor))
+ (ref-set list-ref
+ (cons item (take soft-limit @list-ref)))
+ (ref-set list-ref (cons item @list-ref))))
+
;; Formatters
(def yyyy-mm-dd-formatter (new SimpleDateFormat "yyyy-MM-dd"))