Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 04E017501 for ; Sun, 11 Dec 2011 03:09:09 +0000 (UTC) Received: (qmail 5593 invoked by uid 500); 11 Dec 2011 03:09:07 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 5460 invoked by uid 500); 11 Dec 2011 03:09:06 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 5450 invoked by uid 99); 11 Dec 2011 03:09:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Dec 2011 03:09:04 +0000 X-ASF-Spam-Status: No, hits=4.0 required=5.0 tests=FREEMAIL_REPLY,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of danbryan@gmail.com designates 209.85.210.180 as permitted sender) Received: from [209.85.210.180] (HELO mail-iy0-f180.google.com) (209.85.210.180) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Dec 2011 03:09:00 +0000 Received: by iaae16 with SMTP id e16so9177980iaa.11 for ; Sat, 10 Dec 2011 19:08:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:message-id:in-reply-to:references:subject:x-mailer :mime-version:content-type; bh=cbsu2iYOMhW7gOWV3DMRksbVEkpRRYpj4BcxKde584c=; b=dnFwTNaHFSTQl9zKjDam03AkKbY/+44hpeSwyKDQm/w1v1P4ituh0wWJ0Aqc9kTywd ztzs8ExFPoVBFZ/TBGiE+ps/eFGmhCZtlMapqHseEU5JNIYvKOK0jgAS6Kg/0xLwczyd unBYPfW4EoC/wV2WcAv/by//UGPUbhV9rzscc= Received: by 10.43.50.67 with SMTP id vd3mr7539604icb.10.1323572919121; Sat, 10 Dec 2011 19:08:39 -0800 (PST) Received: from lesta.local (14-200-158-247.static.tpgi.com.au. [14.200.158.247]) by mx.google.com with ESMTPS id wo4sm29476286igc.5.2011.12.10.19.08.36 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 10 Dec 2011 19:08:37 -0800 (PST) Date: Sun, 11 Dec 2011 14:08:33 +1100 From: Daniel Bryan To: user@couchdb.apache.org Message-ID: In-Reply-To: References: <20111209114251.GA5674@urvas> Subject: Re: advice on how to get equal number of items of different types from db X-Mailer: sparrow 1.4.2 (build 959.4) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="4ee41eb1_7644a45c_8ba" --4ee41eb1_7644a45c_8ba Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline A show function is probably the immediate solution, but I'd also suggest = thinking about why you're experiencing this problem in the first place: is the data transmission with the whole document really that much=3F Is t= his a security problem=3F are you sure you aren't overestimating the overhead of doing several sepa= rate AJAX requests=3F If you're requesting conceptually discrete things t= hen this seems architecturally correct if you really are going to have high volumes of GET requests for this dat= a, maybe you should consider restructuring your data=3F Is it really corr= ect for your application logic for it to be organised in this way=3F On Saturday, 10 December 2011 at 3:48 AM, Zachary Zolton wrote: > Bryan, > =20 > The CouchDB way to get back three different types of data would be to > make three view queries. If your problem is that it feels inelegant to > deal with those asynchronous calls, then you should look into an > asynchronous flow control library. > =20 > Here are a couple options: > =20 > jQuery Deferreds (in 1.5+) > http://www.erichynds.com/jquery/using-deferreds-in-jquery/ > =20 > =46low-JS > https://github.com/willconant/flow-js > =20 > =20 > Cheers, > =20 > Zach > =20 > On =46ri, Dec 9, 2011 at 5:42 AM, Rogut=C3=ABs Sparnuotos > wrote: > > bryan rasmussen (2011-12-09 10:01): > > > Hi, > > > =20 > > > I have a db where items in the db are of different types, lets say > > > type A, B, and C. > > > There are a lot of items in the db, and I am returning 60 at a time= in > > > my view. I could theoretically end up in a situation where my first= > > > 1000+ results are of type A when what I want is an even mix of typ= e > > > A,B and C. > > > =20 > > > I could of course do a view for each type but this is problematic i= n > > > that my view is called at the application's load via Ajax, and I do= n't > > > want to send off 3 requests at that time. > > > =20 > > > So what I want is a view or mapreduce or other Couchdb functionalit= y > > > that allows me to return a mix of my types=3F > > > =20 > > > Any pointers, suggestions=3F > > > =20 > > > Thanks, > > > Bryan Rasmussen > > > =20 > > =20 > > =20 > > I would be more worried about 3 separate views than about 3 requests > > (especially when they are async). > > =20 > > 1. Create one view like > > emit(=5Bdoc.type, doc.sort=5Fcriteria=5D, null) > > and query it like > > GET =3Fstartkey=3D=5B=22A=22=5D&endkey=3D=5B=22A=22, =7B=7D=5D&li= mit=3D10 > > GET =3Fstartkey=3D=5B=22B=22=5D&endkey=3D=5B=22B=22, =7B=7D=5D&li= mit=3D10 > > GET =3Fstartkey=3D=5B=22C=22=5D&endkey=3D=5B=22C=22, =7B=7D=5D&li= mit=3D10 > > 2. Get everything client side and filter through. > > 3. Make your documents help you. =46or example, if I needed to return= a > > matching triplet of A, B, C, I would keep an index or something: > > =7B=22type=22: =22A=22, =22typeindex=22: 1=7D > > =7B=22type=22: =22B=22, =22typeindex=22: 1=7D > > =7B=22type=22: =22C=22, =22typeindex=22: 1=7D > > =7B=22type=22: =22A=22, =22typeindex=22: 2=7D > > and in a view: > > emit(doc.typeindex + doc.type, null) > > =20 > > -- > > -- Rogut=C3=ABs Sparnuotos > > =20 > =20 > =20 > =20 --4ee41eb1_7644a45c_8ba--