# Used to remove #related_posts so that it can be overridden defself.included(klass) klass.class_eval do remove_method :related_posts end end
# Calculate related posts. # # Returns [<Post>] defrelated_posts(posts) return [] unless posts.size > 1 highest_freq = Jekyll::Post.tag_freq(posts).values.max related_scores = Hash.new(0) posts.each do|post| post.tags.each do|tag| ifself.tags.include?(tag) && post != self cat_freq = Jekyll::Post.tag_freq(posts)[tag] related_scores[post] += (1+highest_freq-cat_freq) end end end
Jekyll::Post.sort_related_posts(related_scores) end
moduleClassMethods # Calculate the frequency of each tag. # # Returns {tag => freq, tag => freq, ...} deftag_freq(posts) return @tag_freq if @tag_freq @tag_freq = Hash.new(0) posts.each do|post| post.tags.each {|tag| @tag_freq[tag] += 1} end @tag_freq end
# Sort the related posts in order of their score and date # and return just the posts defsort_related_posts(related_scores) related_scores.sort do|a,b| if a[1] < b[1] 1 elsif a[1] > b[1] -1 else b[0].date <=> a[0].date end end.collect {|post,freq| post} end end
end
moduleJekyll classPost include RelatedPosts extend RelatedPosts::ClassMethods end end
本文簡單說明如何設定兩台 MySQL server,讓它們彼此互相備份資料 (Master-master 模式)。雖然這樣的設定通常是支援高可用性 (high availability) 平台的一部分,但本文不包含如何完成其他 HA 的工作。設定兩台 MySQL 伺服器互相備份,主要目的就是要確認資料的安全性;同時也提高可用性。