Author: sevein
Date: Wed Feb 15 13:55:09 2012
New Revision: 10899
Log:
Move the code executed when context.load_factories is triggered to a filter
class called QubitMeta, executed after the settings filter, so cached settings
can be used. It is reducing the SQL queries from 41 to 26 in the front page
(with cache enabled).
Added:
trunk/lib/filter/QubitMeta.class.php
Modified:
trunk/apps/qubit/config/filters.yml
trunk/apps/qubit/config/qubitConfiguration.class.php
trunk/apps/qubit/modules/sfInstallPlugin/config/filters.yml
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/config/filters.yml
Modified: trunk/apps/qubit/config/filters.yml
==============================================================================
--- trunk/apps/qubit/config/filters.yml Wed Feb 15 13:54:15 2012 (r10898)
+++ trunk/apps/qubit/config/filters.yml Wed Feb 15 13:55:09 2012 (r10899)
@@ -19,5 +19,8 @@
QubitSslRequirement:
class: QubitSslRequirementFilter
+QubitMeta:
+ class: QubitMeta
+
cache: ~
execution: ~
Modified: trunk/apps/qubit/config/qubitConfiguration.class.php
==============================================================================
--- trunk/apps/qubit/config/qubitConfiguration.class.php Wed Feb 15
13:54:15 2012 (r10898)
+++ trunk/apps/qubit/config/qubitConfiguration.class.php Wed Feb 15
13:55:09 2012 (r10899)
@@ -22,79 +22,6 @@
const
VERSION = '1.2';
- public function contextLoadFactories(sfEvent $event)
- {
- $context = $event->getSubject();
-
- $criteria = new Criteria;
- $criteria->add(QubitSetting::NAME, 'siteTitle');
-
- try
- {
- if (1 == count($query = QubitSetting::get($criteria)))
- {
- $context->response->addMeta('title', $query[0]->__get('value',
array('cultureFallback' => true)));
- }
- }
- catch (PropelException $e)
- {
- // Silently swallow PropelException in install
- if ('sfInstallPlugin' != $context->request->module)
- {
- throw $e;
- }
- }
-
- $criteria = new Criteria;
- $criteria->add(QubitSetting::NAME, 'siteDescription');
-
- try
- {
- if (1 == count($query = QubitSetting::get($criteria)))
- {
- $context->response->addMeta('description', $query[0]->__get('value',
array('cultureFallback' => true)));
- }
- }
- catch (PropelException $e)
- {
- // Silently swallow PropelException in install
- if ('sfInstallPlugin' != $context->request->module)
- {
- throw $e;
- }
- }
-
- foreach (array('actor_template', 'informationobject_template',
'repository_template') as $name)
- {
- if (isset($context->request[$name]))
- {
- $context->routing->setDefaultParameter($name,
$context->request[$name]);
- }
- else
- {
- $criteria = new Criteria;
- $criteria->add(QubitSetting::NAME, substr($name, 0, -9));
- $criteria->add(QubitSetting::SCOPE, 'default_template');
-
- try
- {
- if (1 == count($query = QubitSetting::get($criteria)))
- {
- $context->routing->setDefaultParameter($name,
$query[0]->__get('value', array('sourceCulture' => true)));
- }
- }
- catch (PropelException $e)
- {
- // Silently swallow PropelException in install
- if ('sfInstallPlugin' != $context->request->module)
- {
- throw $e;
- }
- }
- }
- }
- }
-
public function responseFilterContent(sfEvent $event, $content)
{
ProjectConfiguration::getActive()->loadHelpers('Javascript');
@@ -104,7 +31,6 @@
public function configure()
{
- $this->dispatcher->connect('context.load_factories', array($this,
'contextLoadFactories'));
$this->dispatcher->connect('response.filter_content', array($this,
'responseFilterContent'));
}
Modified: trunk/apps/qubit/modules/sfInstallPlugin/config/filters.yml
==============================================================================
--- trunk/apps/qubit/modules/sfInstallPlugin/config/filters.yml Wed Feb 15
13:54:15 2012 (r10898)
+++ trunk/apps/qubit/modules/sfInstallPlugin/config/filters.yml Wed Feb 15
13:55:09 2012 (r10899)
@@ -12,5 +12,8 @@
QubitSslRequirement:
enabled: false
+QubitMeta:
+ enabled: false
+
cache: ~
execution: ~
Added: trunk/lib/filter/QubitMeta.class.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/lib/filter/QubitMeta.class.php Wed Feb 15 13:55:09 2012
(r10899)
@@ -0,0 +1,43 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+class QubitMeta extends sfFilter
+{
+ public function execute($filterChain)
+ {
+ $context = $this->getContext();
+
+ $context->response->addMeta('title', sfConfig::get('app_siteTitle'));
+ $context->response->addMeta('description',
sfConfig::get('app_siteDescription'));
+
+ foreach (array('actor_template', 'informationobject_template',
'repository_template') as $name)
+ {
+ if (isset($context->request[$name]))
+ {
+ $context->routing->setDefaultParameter($name,
$context->request[$name]);
+ }
+ else
+ {
+ $context->routing->setDefaultParameter($name,
sfConfig::get('app_'.substr($name, 0, -9)));
+ }
+ }
+
+ $filterChain->execute();
+ }
+}
Modified: trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/config/filters.yml
==============================================================================
--- trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/config/filters.yml
Wed Feb 15 13:54:15 2012 (r10898)
+++ trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/config/filters.yml
Wed Feb 15 13:55:09 2012 (r10899)
@@ -19,5 +19,8 @@
QubitSslRequirement:
enabled: false
+QubitMeta:
+ enabled: false
+
cache: ~
execution: ~
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.