lib/ayadn/databases.rb in ayadn-1.2.8 vs lib/ayadn/databases.rb in ayadn-1.2.9
- old
+ new
@@ -15,39 +15,28 @@
@blacklist = self.init "#{Settings.config[:paths][:db]}/blacklist.db"
@bookmarks = self.init "#{Settings.config[:paths][:db]}/bookmarks.db"
@nicerank = self.init "#{Settings.config[:paths][:db]}/nicerank.db"
end
+ def self.all_dbs
+ [@users, @index, @pagination, @aliases, @blacklist, @bookmarks, @nicerank]
+ end
+
def self.close_all
- if @nicerank.size > 5000
- limit = Time.now - 432000
+ if @nicerank.size > 10000
+ limit = Time.now - (3600 * 168)
@nicerank.each {|k,v| @nicerank.delete(k) if v[:cached] < limit}
- if @nicerank.size > 5000
- limit = Time.now - 86400
+ if @nicerank.size > 10000
+ limit = Time.now - (3600 * 48)
@nicerank.each {|k,v| @nicerank.delete(k) if v[:cached] < limit}
end
end
- if Settings.options[:timeline][:show_debug] == true
- puts "/////\nSETTINGS\n"
- jj JSON.parse((Settings.config).to_json)
- jj JSON.parse((Settings.options).to_json)
- puts "/////\n\n"
+ Debug.db all_dbs
- puts ">>>>>\nDATABASES\n"
- [@users, @index, @pagination, @aliases, @blacklist, @bookmarks, @nicerank].each do |db|
- puts "Path:\t#{db.file}\nLength:\t#{db.size}\nSize:\t#{db.bytesize / 1024}KB"
- end
- puts ">>>>>\n\n"
-
- puts "^^^^^\nTOKEN\n"
- puts Settings.user_token
- puts "^^^^^\n\n"
- end
-
- [@users, @index, @pagination, @aliases, @blacklist, @bookmarks, @nicerank].each do |db|
+ all_dbs.each do |db|
db.flush
db.compact
db.close
end
end
@@ -61,57 +50,41 @@
Daybreak::DB.new "#{path}"
# end
end
def self.add_niceranks niceranks
- niceranks.each do |id,infos|
- @nicerank[id] = infos
- end
+ niceranks.each {|id,infos| @nicerank[id] = infos}
end
def self.get_niceranks user_ids
ids = {}
- user_ids.each do |id|
- ids[id] = @nicerank[id]
- end
+ user_ids.each {|id| ids[id] = @nicerank[id]}
ids
end
def self.add_mention_to_blacklist(target)
- target.each do |username|
- @blacklist[username.downcase] = :mention
- end
+ target.each {|username| @blacklist[username.downcase] = :mention}
end
def self.add_client_to_blacklist(target)
- target.each do |source|
- @blacklist[source.downcase] = :client
- end
+ target.each {|source| @blacklist[source.downcase] = :client}
end
def self.add_hashtag_to_blacklist(target)
- target.each do |tag|
- @blacklist[tag.downcase] = :hashtag
- end
+ target.each {|tag| @blacklist[tag.downcase] = :hashtag}
end
def self.remove_from_blacklist(target)
- target.each do |el|
- @blacklist.delete(el.downcase)
- end
+ target.each {|el| @blacklist.delete(el.downcase)}
end
def self.import_blacklist(blacklist)
new_list = self.init blacklist
new_list.each {|name,type| @blacklist[name] = type}
new_list.close
end
def self.convert_blacklist
dummy = {}
- @blacklist.each do |v,k|
- dummy[v.downcase] = k
- end
+ @blacklist.each {|v,k| dummy[v.downcase] = k}
@blacklist.clear
- dummy.each do |v,k|
- @blacklist[v] = k
- end
+ dummy.each {|v,k| @blacklist[v] = k}
end
def self.save_max_id(stream)
@pagination[stream['meta']['marker']['name']] = stream['meta']['max_id']
end
@@ -132,41 +105,33 @@
new_aliases.each {|al,id| @aliases[al] = id}
new_aliases.close
end
def self.get_alias_from_id(channel_id)
- @aliases.each do |al, id|
- return al if id == channel_id
- end
+ @aliases.each {|al, id| return al if id == channel_id}
nil
end
def self.save_indexed_posts(posts)
@index.clear
- posts.each do |id, hash|
- @index[id] = hash
- end
+ posts.each {|id, hash| @index[id] = hash}
end
def self.get_index_length
@index.length
end
def self.get_post_from_index(number)
unless number > @index.length || number <= 0
- @index.each do |id, values|
- return values if values[:count] == number
- end
+ @index.each {|id, values| return values if values[:count] == number}
else
- puts "\nNumber must be in the range of the indexed posts.\n".color(:red)
+ puts Status.must_be_in_index
Errors.global_error("databases/get_post_from_index", number, "out of range")
end
end
def self.add_to_users_db_from_list(list)
- list.each do |id, content_array|
- @users[id] = {content_array[0] => content_array[1]}
- end
+ list.each { |id, content_array| @users[id] = {content_array[0] => content_array[1]} }
end
def self.add_to_users_db(id, username, name)
@users[id] = {username => name}
end