From c24dc08e3be0cb3cae761c5ede6aa637e207715a Mon Sep 17 00:00:00 2001 From: Henri Bergius Date: Fri, 14 Mar 2008 16:55:19 +0200 Subject: [PATCH] Use custom views for faster reporting --- plugins/openpsa/export-expenses.php | 16 +++++----------- plugins/openpsa/export-hours.php | 17 ++++++----------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/plugins/openpsa/export-expenses.php b/plugins/openpsa/export-expenses.php index e88f0bd..b4eb5cc 100644 --- a/plugins/openpsa/export-expenses.php +++ b/plugins/openpsa/export-expenses.php @@ -16,19 +16,13 @@ $expenses = array(); $total_expenses = array(); // Construct the view -//$view = $couchdb->newView(); -//$view->function = "function(doc) { return doc; }"; -//$hour_reports = $view->documents(); +$view = $couchdb->newView(); +$view->function = "function(doc) { if (doc.value._type == 'expense') { map(null, doc); }}"; +$results = $view->documents(); -$everything = $couchdb->view('_all_docs')->documents(); -foreach ($everything as $object) +foreach ($results as $result) { - $document = $couchdb->get($object->id); - if ($document->value->_type != 'expense') - { - continue; - } - + $document = $result->value; $creator = $document->value->metadata->creator->val; if (!isset($expenses[$creator])) { diff --git a/plugins/openpsa/export-hours.php b/plugins/openpsa/export-hours.php index 3d4783c..9957b3d 100644 --- a/plugins/openpsa/export-hours.php +++ b/plugins/openpsa/export-hours.php @@ -16,19 +16,14 @@ $hours = array(); $total_hours = array(); // Construct the view -//$view = $couchdb->newView(); -//$view->function = "function(doc) { return doc; }"; -//$hour_reports = $view->documents(); +$view = $couchdb->newView(); +$view->function = "function(doc) { if (doc.value._type == 'hour_report') { map(null, doc); }}"; +$results = $view->documents(); -$everything = $couchdb->view('_all_docs')->documents(); -foreach ($everything as $object) +//$everything = $couchdb->view('_all_docs')->documents(); +foreach ($results as $result) { - $document = $couchdb->get($object->id); - if ($document->value->_type != 'hour_report') - { - continue; - } - + $document = $result->value; $creator = $document->value->metadata->creator->val; if (!isset($hours[$creator])) { -- 2.11.4.GIT