Return-Path: Delivered-To: apmail-incubator-couchdb-commits-archive@locus.apache.org Received: (qmail 32089 invoked from network); 29 Jun 2008 00:04:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Jun 2008 00:04:15 -0000 Received: (qmail 20567 invoked by uid 500); 29 Jun 2008 00:04:16 -0000 Delivered-To: apmail-incubator-couchdb-commits-archive@incubator.apache.org Received: (qmail 20539 invoked by uid 500); 29 Jun 2008 00:04:16 -0000 Mailing-List: contact couchdb-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-dev@incubator.apache.org Delivered-To: mailing list couchdb-commits@incubator.apache.org Received: (qmail 20085 invoked by uid 99); 29 Jun 2008 00:04:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Jun 2008 17:04:15 -0700 X-ASF-Spam-Status: No, hits=-1998.5 required=10.0 tests=ALL_TRUSTED,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.130] (HELO eos.apache.org) (140.211.11.130) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 Jun 2008 00:03:33 +0000 Received: from eos.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id A360A11155 for ; Sun, 29 Jun 2008 00:03:23 +0000 (GMT) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Apache Wiki To: couchdb-commits@incubator.apache.org Date: Sun, 29 Jun 2008 00:03:23 -0000 Message-ID: <20080629000323.3727.95261@eos.apache.org> Subject: =?utf-8?q?=5BCouchdb_Wiki=5D_Update_of_=22Reg=C3=A9n=C3=A9rationVues?= =?utf-8?q?=C3=80laMiseAjour=22_by_BenoitC?= X-Virus-Checked: Checked by ClamAV on apache.org Dear Wiki user, You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification. The following page has been changed by BenoitC: http://wiki.apache.org/couchdb/Reg%c3%a9n%c3%a9rationVues%c3%80laMiseAjour New page: #language fr = Mettre à jour les vues lors de l'enregistrement d'un document = Par défaut CouchDB regénère les vues la première fois qu'elles sont appelées. Ce comportement est adéquat pour la plupart des cas dans la mesure où il optimise l'utilisation des resources sur le serveur de base de données. Mais dans certains cas, il est préférables d'avoir rapidement des vues à jour malgré le coût créée par une mise à jour systématique à chaque fois que le serveur reçoit une mise à jour. On peut réaliser cela en fournissant un script de mise à jour qui appelle les vues lorsque cela est nécessaire. == Exemple utilisant ruby == === couch.ini === Ajoutez la lignes suivante au fichier couch.ini {{{ DbUpdateNotificationProcess=/PATH/TO/view_updater.rb }}} === view_updater.rb === Le script suivant met à jour les vues toutes les 10 mises à jour reçues par la base de données ou une fois / secondes lorsque le nombre d'enregistrement est important {{{ #!/usr/bin/ruby ################### # CONF # ################### # The smallest amount of changed documents before the views are updated MIN_NUM_OF_CHANGED_DOCS = 10 # URL to the DB on the CouchDB server URL = "http://localhost:5984" # Set the minimum pause between calls to the database PAUSE = 1 # seconds # One entry for each design document # in each database VIEWS = {"DATABASE_NAME" => ["list_of/design_documents", "another/design_document"], "recipes" => ["category/most_popular"], "ingredients" => ["by/price"]} ################### # RUNTIME # ################### run = true number_of_changed_docs = {} threads = [] # Updates the views threads << Thread.new do while run do number_of_changed_docs.each_pair do |db_name, number_of_docs| if number_of_docs >= MIN_NUM_OF_CHANGED_DOCS # Reset the value number_of_changed_docs[db_name] = 0 # If there are views in the database, get them if VIEWS[db_name] VIEWS[db_name].each do |view| `curl #{URL}/#{db_name}/_view/#{view}?count=0` end end end end # Pause before starting over again sleep PAUSE end end # Receives the update notification from CouchDB threads << Thread.new do while run do puts "Waiting for input:" update_call = gets # When CouchDB exits the script gets called with # a never ending series of nil if update_call == nil run = false else # Get the database name out of the call data # The data looks somethind like this: # {"type":"updated","db":"DB_NAME"}\n update_call =~ /\"db\":\"(\w+)\"/ database_name = $1 # Set to 0 if it hasn't been initialized before number_of_changed_docs[$1] ||= 0 # Add one pending changed document to the list of documents # in the DB number_of_changed_docs[$1] += 1 end end end # Good bye threads.each {|thr| thr.join} }}} view_updater.rb doit être exécutable par CouchDB .