Permalink
Browse files

Now use a hardcoded IP address so we aren't doing

so many DNS lookups
  • Loading branch information...
1 parent 6986e50 commit cfde529492e607385a7d503b063696a0a597560f @hcatlin committed Oct 14, 2010
Showing with 6 additions and 16 deletions.
  1. +4 −7 app/models/server.rb
  2. +1 −1 spec/models/article_spec.rb
  3. +1 −1 spec/requests/articles_spec.rb
  4. +0 −7 spec/requests/statistics_spec.rb
View
@@ -4,13 +4,13 @@
# Server is a model class that represents a media wiki server.
# This is the base model for getting articles and eventually login-logout stuff.
class Server
+ @@ip = "208.80.152.2"
@@conn = Curl::Easy.new
@@conn.follow_location = true
@@conn.max_redirects = 4
@@conn.connect_timeout = 5
@@conn.dns_cache_timeout = 30 * 60 # Keep the DNS cache for 30 minutes
@@conn.timeout = 20
- #@@conn.proxy_url = "208.80.152.2"
@@conn.headers = {"Accept-Encoding" => "gzip,deflate",
"User-Agent" => "Mozilla/5.0 Wikimedia Mobile",
"Accept-Charset" => "utf-8;q=0.7,*;q=0.7"}
@@ -29,11 +29,7 @@ def initialize(language_code = "en", opts = {})
# What is the base URL for this server?
def base_url
- if @port.to_i != 80
- "http://#{@host}:#{@port}"
- else
- "http://#{@host}"
- end
+ "http://#{@@ip}:#{@port}"
end
def file(title, variant = "wiki")
@@ -85,7 +81,8 @@ def fetch_from_web(path)
retry_counter = 0
time_to "download article from web" do
begin
- @@conn.url = base_url + path
+ Merb.logger.debug "URL: " + (@@conn.url = base_url + path)
+ Merb.logger.debug "Host: " + (@@conn.headers['Host'] = @host)
@@conn.perform
@@conn
rescue Curl::Err::HostResolutionError, Curl::Err::GotNothingError, Curl::Err::ConnectionFailedError, Curl::Err::PartialFileError, Curl::Err::TimeoutError
@@ -11,7 +11,7 @@
Article.any_instance.stubs(:device).returns @device
# Stubs out networking
- Curl::Easy.any_instance.stubs(:perform).returns ARTICLE_GO_MAN_GO
+ Server.any_instance.stubs(:fetch_from_web).returns ARTICLE_GO_MAN_GO
end
it "should grab an article" do
@@ -4,7 +4,7 @@
describe "articles" do
before :all do
# Stubs out networking
- Curl::Easy.any_instance.stubs(:perform).returns ARTICLE_GO_MAN_GO
+ Server.any_instance.stubs(:fetch_from_web).returns ARTICLE_GO_MAN_GO
Article.any_instance.stubs(:device).returns stub(:parser => "html")
end
@@ -1,7 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
-
-describe "/statistics" do
- before(:each) do
- @response = request("/statistics")
- end
-end

0 comments on commit cfde529

Please sign in to comment.