At 17:50 -0800 2/2/09, Rich Morin wrote:
> The act of looking up a document in CouchRest is updating
> _rev on the view that it uses. This seems inefficient.
>
> * Is there a reason for this behavior?
>
> * If not, is there a way to prevent it?
>
> I have a test script (http://pastie.org/377884) which looks
> up a document by its "p_uuidc" field. Using Futon, I can
> confirm that _rev is changing in the _design document when
> I run the script.
>
> Alternatively, when I use a Rack-based forwarding/tracing
> script, I see a PUT for the _design document, despite the
> fact that I'm not asking for any such thing.
>
> Wazzup?
At 18:14 -0800 2/2/09, Chris Anderson wrote:
> On Mon, Feb 2, 2009 at 5:50 PM, Rich Morin <r...@cfcl.com> wrote:
>> * Is there a reason for this behavior?
>
> No. It's ready to be optimized away.
I'm delighted to hear that! I was afraid it was some sort
of low-level design issue.
> There's a mailing list for CouchRest here:
>
> http://groups.google.com/group/couchrest
Cool; I hadn't know about that. Hi, folks!
> I hope that the design doc is only being updated once per
> script load - eg running 2 view requests should only update
> the design doc once.
Using my tracing app, I can confirm that only a single PUT is
done per run of the test script.
> Design docs should not need to be PUT for each definition
> of the model class. It should be simple to make a fix for
> getting the design doc to see if it matches the ruby view
> definition.
>
> Do you feel up to making a patch? Running `rake` in the
> CouchRest source directory should give you a passing test
> suite, so patching it is just a matter of fixing the bug
> without breaking any of the other specs.
I'll pull down the code and take a look, but I don't have
much confidence in my ability to fix it. So, if anyone can
offer a hint (or simply wants to jump in), please do so...
-r
--
http://www.cfcl.com/rdm Rich Morin
http://www.cfcl.com/rdm/resume r...@cfcl.com
http://www.cfcl.com/rdm/weblog +1 650-873-7841
Technical editing and writing, programming, and web development
I don't know if this would make a noticeable difference in
performance for most users (is a GET cheaper than a PUT?).
Philosophically, however, it seems wrong to update a _rev
when no writing has been requested by the client program.
In any case, does anyone have any pointers to offer for
where this fix should go in the code?
The suggested fix might also help in my (quite unusual)
situation. I'm running untrusted code which may try to do
Bad Things to the database. If I can simply turn off all
PUT requests (including ones that update views), that will
keep a lot of nastiness from happening.
The way it might play out is that the untrusted code would
try a search, specifying a named view. If the view code
differs from that in the database, CouchRest would try to
do a PUT. I'd kill that, and the untrusted code would die.
Is this anything like a reasonable approach?
You'd probably want to start by adding some puts traces to
CR::Model#refresh_design_doc and the code that calls it.
That's likely where you can avoid extra saves if you don't need them.
I think this problem is unrelated to untrusted views problem, as the
CouchRest views are generated from Ruby code. The changes you're
talking about making shouldn't have any effect other than optimizing
database chatter.
Unless there will be Ruby code in your system that you can't trust,
you'd probably do better to think of the trust boundary as outside of
your application server.
--
Chris Anderson
http://jchris.mfdz.com
I think CouchRest::Model has an option to define the type field.
the use_view method looks intriguing. is it available on github? with
some docs and a test case I'd be happy to add it.
Darn, I think I lost a patch from someone back along the way. I
totally support making couchrest-type configurable.