couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <rnew...@apache.org>
Subject Re: View cache invalidation
Date Wed, 11 Apr 2012 20:09:05 GMT
Try this instead;

function(doc) {
  if(!doc.businessHours) {
    return;
  }
  for (var day in doc.businessHours) {
    emit(day, doc);
  }
}

Query the view with ?key="s", for example. I would also recommend
emitting null instead of doc and using include_docs=true.

On 11 April 2012 15:24, Julien Dreux <jdreux@justlexit.com> wrote:
> Thank you all for your help. Here's the view that is causing issues. We are
> using the local time to get the current day of the week. See below.
>
> The documents represent opening hours and are of the form:
>
> {
> businessHours: {
>   s: ['0800','2300'],
>   m: ['0700','2330'],
>  ...
>
>  }
> }
>
> function(doc) {
>  if(doc.businessHours) {
>    var daysArr = new Array('s','m','t','w','h','f','a');
>    var day = daysArr[new Date().getDay()];
>    emit(parseInt(doc.businessHours[day][0].indexOf('0') == 0 ?
> doc.businessHours[day][0].substring(1) : doc.businessHours[day][0]), doc)};
> }
>
> Thank you for your help.
> *
> *
> *JULIEN DREUX*
> jdreux@justlexit.com
> 514 812-8084
> www.justlexit.com
>
>
> On Wed, Apr 11, 2012 at 3:02 PM, Robert Newson <rnewson@apache.org> wrote:
>
>> Hi Julien,
>>
>> This is a bug in your view, rather than a problem with CouchDB. A view
>> is built by reading the _changes feed for the database, and only
>> updates to documents will cause their corresponding rows in the view
>> to be recalculated. This is all by design.
>>
>> If you give more details, we can help you fix your view. Someone has
>> already noted the general shape of the solution, emitting the
>> timestamp in the key and selecting slices with startkey/endkey.
>>
>> B.
>>
>>
>> On 11 April 2012 14:50, Aurélien Bénel <aurelien.benel@utt.fr> wrote:
>> >> What are the implications of doing this?
>> >
>> > MapReduce provides you with a very efficient cache mechanism but to
>> work, views must be completely context-independent.
>> >
>> >> What can we do to still keep our views with up to date data?
>> >
>> > Set your one week slot outside the view definition: either in the view
>> URL (with startkey/endkey) or in a list.
>> >
>> > Regards,
>> >
>> > Aurélien
>>

Mime
View raw message