summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Legler <alex@a3li.li>2015-12-13 13:29:59 +0100
committerAlex Legler <alex@a3li.li>2015-12-13 13:29:59 +0100
commit1f4743f2ae61a7f443980359303d6d631b2426fc (patch)
treedb1a8aafc861eb8fcbf15993090784fa86a55eea /lib
parentUse protocol-relative URI for the favicon (diff)
downloadfrontend-1f4743f2ae61a7f443980359303d6d631b2426fc.tar.gz
frontend-1f4743f2ae61a7f443980359303d6d631b2426fc.tar.bz2
frontend-1f4743f2ae61a7f443980359303d6d631b2426fc.zip
Style fixes
Diffstat (limited to 'lib')
-rw-r--r--lib/cache.rb17
-rw-r--r--lib/helpers.rb28
-rw-r--r--lib/index.rb14
3 files changed, 30 insertions, 29 deletions
diff --git a/lib/cache.rb b/lib/cache.rb
index f635114..262003e 100644
--- a/lib/cache.rb
+++ b/lib/cache.rb
@@ -1,5 +1,7 @@
require 'date'
+# Caches the message count for each email
+# I guess this operation is/was expensive at some point.
class MessageCountCache
include Singleton
CACHE_SECONDS = 3600
@@ -27,16 +29,16 @@ class MessageCountCache
end
private
+
def update?
- if ((DateTime.now - @load_date) * 60 * 60 * 24).to_i > CACHE_SECONDS
- update!
- end
+ update! if ((DateTime.now - @load_date) * 60 * 60 * 24).to_i > CACHE_SECONDS
end
end
+# Caches the most recent messages displayed on the front page
class MostRecentMessagesCache
include Singleton
- CACHE_SECONDS=3600
+ CACHE_SECONDS = 3600
def initialize
update!
@@ -61,9 +63,8 @@ class MostRecentMessagesCache
end
private
+
def update?
- if ((DateTime.now - @load_date) * 60 * 60 * 24).to_i > CACHE_SECONDS
- update!
- end
+ update! if ((DateTime.now - @load_date) * 60 * 60 * 24).to_i > CACHE_SECONDS
end
-end \ No newline at end of file
+end
diff --git a/lib/helpers.rb b/lib/helpers.rb
index 873d50f..3ed4f51 100644
--- a/lib/helpers.rb
+++ b/lib/helpers.rb
@@ -8,7 +8,7 @@ helpers do
def list_check
unless [$config['active_lists'], $config['frozen_lists']].flatten.include?(params[:list])
status 404
- body "List not found"
+ body 'List not found'
return false
end
@@ -16,9 +16,9 @@ helpers do
end
def monthint_to_link(monthint)
- date = DateTime.parse("%s-%s-01" % [monthint[0..3], monthint[4..5]])
+ date = DateTime.parse('%s-%s-01' % [monthint[0..3], monthint[4..5]])
- "<a href=\"threads/%s/\">%s</a>" % [date.strftime('%Y-%m'), date.strftime('%Y %B')]
+ '<a href="threads/%s/">%s</a>' % [date.strftime('%Y-%m'), date.strftime('%Y %B')]
end
def date_format(date)
@@ -26,11 +26,11 @@ helpers do
end
def to_monthint(year, month)
- ("%i%02i" % [year.to_i, month.to_i]).to_i
+ ('%i%02i' % [year.to_i, month.to_i]).to_i
end
def to_month(year, month)
- date = DateTime.parse("%s-%s-01" % [year, month])
+ date = DateTime.parse('%s-%s-01' % [year, month])
date.strftime('%B %Y')
end
@@ -39,19 +39,19 @@ helpers do
end
def u(text)
- ERB::Util::url_encode(text)
+ ERB::Util.url_encode(text)
end
# This method strips domains from header fields.
def strip_email_headers(ary)
[ary].flatten.map do |email|
- email.gsub(/@(\S*?)('|"|>|$)/) do |s|
+ email.gsub(/@(\S*?)('|"|>|$)/) do
if $1 == 'gentoo.org'
"@g.o#{$2}"
elsif $1 == 'lists.gentoo.org'
"@l.g.o#{$2}"
else
- domain, dot, tld = $1.rpartition '.'
+ domain, _dot, tld = $1.rpartition '.'
"@#{'×' * domain.length}.#{tld}#{$2}"
end
end
@@ -60,10 +60,10 @@ helpers do
# This method is meant to strip emails from free text, not header fields
def strip_email(str)
- str.gsub(/([a-zA-Z0-9._%+-]+)@([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,10})/) do |s|
- if $2 == 'gentoo' and $3 == 'org'
+ str.gsub(/([a-zA-Z0-9._%+-]+)@([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,10})/) do
+ if $2 == 'gentoo' && $3 == 'org'
"#{$1}@g.o"
- elsif $2 == 'lists.gentoo' and $3 == 'org'
+ elsif $2 == 'lists.gentoo' && $3 == 'org'
"#{$1}@l.g.o"
else
"#{$1}@#{'×' * $2.length}.#{$3}"
@@ -76,7 +76,7 @@ helpers do
end
def msgid_to_gmane(msgid)
- GMANE_FIND + ERB::Util::url_encode(msgid)
+ GMANE_FIND + ERB::Util.url_encode(msgid)
end
def msgid_to_marc(msgid)
@@ -87,7 +87,7 @@ helpers do
# pan.2009.08.28.00.00.38@cox.net
# http://marc.info/?i=pan.2009.08.28.00.00.38%20()%20cox%20!%20net
local, host = msgid.split('@', 2)
- new_msgid = local + ' () ' + host.gsub('.',' ! ')
- MARC_FIND + ERB::Util::url_encode(new_msgid)
+ new_msgid = local + ' () ' + host.gsub('.', ' ! ')
+ MARC_FIND + ERB::Util.url_encode(new_msgid)
end
end
diff --git a/lib/index.rb b/lib/index.rb
index 328b74b..3e88a43 100644
--- a/lib/index.rb
+++ b/lib/index.rb
@@ -18,7 +18,7 @@ def threads_in_month(list, year, month, page)
}
},
sort: {
- date: 'desc',
+ date: 'desc'
}
}
)
@@ -30,7 +30,7 @@ def most_recent(list, n)
size: n,
body: {
sort: {
- date: 'desc',
+ date: 'desc'
}
}
)
@@ -40,7 +40,7 @@ def most_recent(list, n)
else
return result['hits']['hits']
end
-rescue => e
+rescue => _e
[]
end
@@ -58,7 +58,7 @@ def messages_in_month(list, year, month, page)
}
},
sort: {
- date: 'desc',
+ date: 'desc'
}
}
)
@@ -99,7 +99,7 @@ def get_message_count_internal(list)
size: 1,
body: {}
)['hits']['total']
-rescue => e
+rescue => _e
'?'
end
@@ -120,7 +120,7 @@ def get_message(list, hash)
end
def get_parent_data(list, parent_id)
- return nil if parent_id == nil
+ return nil if parent_id.nil?
parent = $es.search(
index: 'ml-' + list,
@@ -135,7 +135,7 @@ def get_parent_data(list, parent_id)
end
def get_child_data(list, parent_id)
- return nil if parent_id == nil
+ return nil if parent_id.nil?
children = $es.search(
index: 'ml-' + list,