Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

use GET requests for get (which I think is the same as queries where …

…the only condition is key == blah), should be much faster and more effecient than building an ad hoc view
  • Loading branch information...
commit bbee5b2b5aa3e96afafe418f4c8de4d9cdc8344c 1 parent c3488e7
Wesley Beary authored

Showing 1 changed file with 38 additions and 16 deletions. Show diff stats Hide diff stats

  1. +38 16 adapters/dm-couchdb-adapter/lib/couchdb_adapter.rb
54 adapters/dm-couchdb-adapter/lib/couchdb_adapter.rb
@@ -120,15 +120,23 @@ def read_many(query)
120 120 if doc['rows']
121 121 Collection.new(query) do |collection|
122 122 doc['rows'].each do |doc|
  123 + data = doc["value"]
123 124 collection.load(
124 125 query.fields.map do |property|
125   - doc["value"][property.field.to_s]
  126 + data[property.field.to_s]
126 127 end
127 128 )
128 129 end
129 130 end
130 131 else
131   - []
  132 + data = doc
  133 + Collection.new(query) do |collection|
  134 + collection.load(
  135 + query.fields.map do |property|
  136 + data[property.field.to_s]
  137 + end
  138 + )
  139 + end
132 140 end
133 141 end
134 142
@@ -136,13 +144,18 @@ def read_one(query)
136 144 doc = request do |http|
137 145 http.request(build_request(query))
138 146 end
139   - unless doc['rows'].empty?
  147 + if doc['rows'] && !doc['rows'].empty?
140 148 data = doc['rows'].first['value']
  149 + elsif !doc['rows']
  150 + data = doc
  151 + end
  152 + if data
141 153 query.model.load(
142 154 query.fields.map do |property|
143 155 data[property.field.to_s]
144 156 end,
145   - query)
  157 + query
  158 + )
146 159 end
147 160 end
148 161
@@ -170,13 +183,31 @@ def normalize_uri(uri_or_options)
170 183 end
171 184
172 185 def build_request(query)
173   - unless query.view
174   - ad_hoc_request(query)
175   - else
  186 + if query.view
176 187 view_request(query)
  188 + elsif query.conditions.length == 1 &&
  189 + query.conditions.first[0] == :eql &&
  190 + query.conditions.first[1].key?
  191 + get_request(query)
  192 + else
  193 + ad_hoc_request(query)
177 194 end
178 195 end
179 196
  197 + def view_request(query)
  198 + uri = "/#{self.escaped_db_name}/" +
  199 + "_view/" +
  200 + "#{query.model.storage_name(self.name)}/" +
  201 + "#{query.view}" +
  202 + "#{query_string(query)}"
  203 + request = Net::HTTP::Get.new(uri)
  204 + end
  205 +
  206 + def get_request(query)
  207 + uri = "/#{self.escaped_db_name}/#{query.conditions.first[2]}"
  208 + request = Net::HTTP::Get.new(uri)
  209 + end
  210 +
180 211 def ad_hoc_request(query)
181 212 if query.order.empty?
182 213 key = "null"
@@ -234,15 +265,6 @@ def ad_hoc_request(query)
234 265 request
235 266 end
236 267
237   - def view_request(query)
238   - uri = "/#{self.escaped_db_name}/" +
239   - "_view/" +
240   - "#{query.model.storage_name(self.name)}/" +
241   - "#{query.view}" +
242   - "#{query_string(query)}"
243   - request = Net::HTTP::Get.new(uri)
244   - end
245   -
246 268 def query_string(query)
247 269 query_string = []
248 270 if query.view_options

0 comments on commit bbee5b2

Please sign in to comment.
Something went wrong with that request. Please try again.