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 CCC3B10872 for ; Fri, 15 Nov 2013 03:28:22 +0000 (UTC) Received: (qmail 24050 invoked by uid 500); 15 Nov 2013 03:28:20 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 24008 invoked by uid 500); 15 Nov 2013 03:28:19 -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 24000 invoked by uid 99); 15 Nov 2013 03:28:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Nov 2013 03:28:18 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of kxepal@gmail.com designates 74.125.82.173 as permitted sender) Received: from [74.125.82.173] (HELO mail-we0-f173.google.com) (74.125.82.173) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Nov 2013 03:28:12 +0000 Received: by mail-we0-f173.google.com with SMTP id u56so2993388wes.18 for ; Thu, 14 Nov 2013 19:27:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=mh8zyie3/F5YUIemR00AtO/Ltl9i5BJVHDRPHlFyu9o=; b=mNVUfeJGwDP8n6Gd0XkO27YOuIBLlUKEiaxuBqSlf+fmAI4IvA7xGDQ4K/YVmeYWkq KpmDQ2uF7PNb3CAUoFYulEqoui/hCHW6kUCBZfWTjnGNEeGRNRyDEKB8GurPa2kJdG84 0ZGBh4gUzmVGYu9hwyQixtUOWHzbEj+XSFHBmU9hZoOkwBJGGcdVNrMuM3WGRQjEoJX/ crvUB7JKcL3eDZVloYPGlkGhU0wNhrGhgWJ8FLp2qaO6br++4VpEyWnn7yZmczsODS6z PsgnL1csg4SRQKY5RBVRSLe5ktPzshYFSb5wYLjUmnSKn96z9i1jzQ/vT6xekAW0ni7q a1Kg== MIME-Version: 1.0 X-Received: by 10.180.223.4 with SMTP id qq4mr1716018wic.35.1384486071963; Thu, 14 Nov 2013 19:27:51 -0800 (PST) Received: by 10.180.24.99 with HTTP; Thu, 14 Nov 2013 19:27:51 -0800 (PST) In-Reply-To: <3A011EF4-4CC1-47D0-BCC5-9D266C579400@programmazione.it> References: <75175787-0293-4918-9CC3-0CE24B8B41C6@programmazione.it> <922FCD26-A6B7-4D45-90F8-18804EF018BA@programmazione.it> <6A445F3B-A89A-455D-AE04-7291687F8EEB@programmazione.it> <3A011EF4-4CC1-47D0-BCC5-9D266C579400@programmazione.it> Date: Fri, 15 Nov 2013 07:27:51 +0400 Message-ID: Subject: Re: show/list From: Alexander Shorin To: "user@couchdb.apache.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Fri, Nov 15, 2013 at 6:44 AM, Filippo Fadda wrote: > On Nov 15, 2013, at 3:06 AM, Alexander Shorin wrote: >> It's always possible to imagine situation when some tool will be >> useless and some other handy and good (: CouchApp is no more, but >> group of design functions as single logical application, that CouchDB >> easily hosts and able to execute by users request. To interact with >> other system or remote services you may use external handlers. To run >> custom background services os_daemons helps much. All these are >> CouchDB features that could be used to solve specific problem. Not >> sure why you're trying to avoid them all. > > I'm not trying to avoid them, at least not all of them. > >> While votes are ok > > Votes are OK, but you can't use a show handler to generate the HTML that = renders the article properties (title, body, etc.) and the sum of his votes= . Instead, working with ElephantOnCouch (or any other clients) you can do t= hat. And you can join documents even if they haven't a score, because Eleph= antOnCouch (only it) returns records for keys don't match any documents. An= d this is free, it's just a query option. I want add this feature to CouchD= B also, but since I'm an Erlang noob, I found easier implement it in my lib= rary. I think the main error is to try to get whole result with single query as you always does with SQL databases. That's wrong way to go. Let's see what we have there: 1. show handler to generate the HTML that renders the article properties (title, body, etc.) - correct 2. the sum of his votes - this is view function and yet another request from client. Join data on client side, not on server. So you have one show function that returns HTML response with some javascript that callbacks on body load view function to get the votes number. This is good application design to have each part of application be standalone and through their aggregation/combination create powerful applications. KISS, DRY and SRP in action. >> , but having article hit as document isn't wise >> approach: to note why share your app url on /. , /r, hn or other >> resource which could generate a lot of hits - you'll quite soon >> realise that some front-end proxy required to buffer updates and >> forward them to CouchDB as bulk update. > > You don't need that. In the Article class there is method named getHitsCo= unt() that query Redis (using the document id) and returns the impressions = count. As I wrote in the mailing list, ElephantOnCouch saves objects and re= creates their instance when you get them with the getDoc() method. This is = an elegant approach. Actually Article is a subclass of Post, etc. We have two different approaches: - yours to generate hit counts on server side - mine to provide additional API for clients to get hit counts using different http resource. You may call it, you may not. If redis is unavailable you don't care at all since your client got the article already, just without hits count. But no one is good since all depends from what requirement are applied to the project. -- ,,,^..^,,,