Gentoo Archives: gentoo-commits

From: Alex Legler <a3li@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/ag-web:master commit in: /, lib/, views/
Date: Wed, 25 Feb 2015 11:00:26
Message-Id: 1424861069.81bc7df02d522a4a43dd73fce4e95b4fec765296.a3li@gentoo
1 commit: 81bc7df02d522a4a43dd73fce4e95b4fec765296
2 Author: Alex Legler <alex <AT> a3li <DOT> li>
3 AuthorDate: Wed Feb 25 10:44:29 2015 +0000
4 Commit: Alex Legler <a3li <AT> gentoo <DOT> org>
5 CommitDate: Wed Feb 25 10:44:29 2015 +0000
6 URL: http://sources.gentoo.org/gitweb/?p=proj/ag-web.git;a=commit;h=81bc7df0
7
8 Cache most recent messages
9
10 ---
11 ag-web.rb | 1 +
12 lib/cache.rb | 34 ++++++++++++++++++++++++++++++++++
13 views/indexentry.erb | 2 +-
14 3 files changed, 36 insertions(+), 1 deletion(-)
15
16 diff --git a/ag-web.rb b/ag-web.rb
17 index fd11ba4..bdac32b 100644
18 --- a/ag-web.rb
19 +++ b/ag-web.rb
20 @@ -26,6 +26,7 @@ $es.transport.reload_connections!
21 $config = YAML.load_file('config.yml')
22
23 MessageCountCache.instance.update!
24 +MostRecentMessagesCache.instance.update!
25
26 get '/:list/report/:msgid' do
27 return unless list_check
28
29 diff --git a/lib/cache.rb b/lib/cache.rb
30 index c2968d1..f635114 100644
31 --- a/lib/cache.rb
32 +++ b/lib/cache.rb
33 @@ -32,4 +32,38 @@ class MessageCountCache
34 update!
35 end
36 end
37 +end
38 +
39 +class MostRecentMessagesCache
40 + include Singleton
41 + CACHE_SECONDS=3600
42 +
43 + def initialize
44 + update!
45 + end
46 +
47 + def update!
48 + @messages ||= {}
49 +
50 + @new_messages = {}
51 + [$config['active_lists'], $config['frozen_lists']].flatten.each do |list|
52 + @new_messages[list] = most_recent(list, 5)
53 + end
54 +
55 + @messages = @new_messages
56 + @load_date = DateTime.now
57 + end
58 +
59 + def [](list)
60 + update?
61 +
62 + @messages[list] || []
63 + end
64 +
65 + private
66 + def update?
67 + if ((DateTime.now - @load_date) * 60 * 60 * 24).to_i > CACHE_SECONDS
68 + update!
69 + end
70 + end
71 end
72 \ No newline at end of file
73
74 diff --git a/views/indexentry.erb b/views/indexentry.erb
75 index 6028ec9..ba6a2cf 100644
76 --- a/views/indexentry.erb
77 +++ b/views/indexentry.erb
78 @@ -18,7 +18,7 @@
79 <th>Subject</th>
80 <th class="ag-mostrecent-table-author">Author</th>
81 </tr>
82 - <% most_recent(list, 5).each do |message| %>
83 + <% MostRecentMessagesCache.instance[list].each do |message| %>
84 <tr>
85 <td><a href="/<%= list %>/message/<%= message['_id'] %>"><%= h message['_source']['subject'] %></a></td>
86 <td><%= h message['_source']['from_realname'] %></td>