Permalink
Browse files

Updated router stuff and sped up article.rb by about 2x

  • Loading branch information...
1 parent 53ded0a commit 55af6a2cb32baaf9b8c1282d10f9ebb3e9e1e054 @wycats wycats committed Nov 30, 2008
Showing with 15 additions and 12 deletions.
  1. +14 −11 app/models/article.rb
  2. +1 −1 config/router.rb
View
@@ -1,13 +1,21 @@
require 'nokogiri'
+require 'curb'
+require 'benchmark'
class Article
attr :title, true
attr :page_name, true
attr :content, true
attr :server, true
+ def self.bench(title, &blk)
+ ret = Benchmark.measure(&blk)
+ puts "#{title}: #{ret.real * 1000}"
+ end
+
def self.find(mediawiki_host, term)
- self.parse(open("http://#{mediawiki_host}/wiki/Special:Search?search=#{term}"))
+ c = Curl::Easy.perform("http://#{mediawiki_host}/wiki/Special:Search?search=#{term}")
+ self.parse(c.body_str)
end
def self.parse(html)
@@ -31,31 +39,26 @@ def self.parse(html)
"div.magnify" #stupid magnify thing
]
- doc = Nokogiri::HTML html
-
- html = doc.inner_html
-
article.server = html.scan(/var wgServer = "([^"]*)";/).first.first
article.page_name = html.scan(/var wgPageName = "([^"]*)";/).first.first
-
- doc = (doc.css "#content").first
+ doc = Nokogiri::XML(html).css("#content").first
+
#remove unnecessary content and edit links
(doc.css items_to_remove.join(",")).remove
- article.title = doc.css(".firstHeading").first.inner_html
+ article.title = doc.css(".firstHeading").first.to_s
- html = doc.inner_html
+ html = doc.to_s
if (html.size > 20000) && !html.include?("No article title matches")
self.headingize(html)
else
html
end
-
+
article.content = html
-
return article
end
View
@@ -36,7 +36,7 @@
# clients from calling your create or destroy actions with a GET
#default_routes
- match(/\/wiki\/(.*)/).to(:controller => "articles", :action => "search", :search => "[1]")
+ match("/wiki/:search", :search => /.*/).to(:controller => "articles", :action => "search")
# Change this for your home page to be available at /
# match('/').to(:controller => 'whatever', :action =>'index')

0 comments on commit 55af6a2

Please sign in to comment.