[Pkg-owncloud-commits] [owncloud] 26/70: do not write to appconfig or preference tables if the value is unchanged
David Prévot
taffit at moszumanska.debian.org
Thu Aug 21 17:40:02 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag v6.0.5RC1
in repository owncloud.
commit 0477d56f5bc52350b444b72bf48a7a8d767ce264
Author: Arthur Schiwon <blizzz at owncloud.com>
Date: Fri Jul 11 00:13:52 2014 +0200
do not write to appconfig or preference tables if the value is unchanged
---
lib/private/appconfig.php | 12 ++++----
lib/private/preferences.php | 11 +++++--
tests/lib/preferences.php | 72 +++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 85 insertions(+), 10 deletions(-)
diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php
index 4f170e0..661ce22 100644
--- a/lib/private/appconfig.php
+++ b/lib/private/appconfig.php
@@ -128,11 +128,13 @@ class OC_Appconfig{
$query = OC_DB::prepare( 'INSERT INTO `*PREFIX*appconfig` ( `appid`, `configkey`, `configvalue` )'
.' VALUES( ?, ?, ? )' );
$query->execute( array( $app, $key, $value ));
- }
- else{
- $query = OC_DB::prepare( 'UPDATE `*PREFIX*appconfig` SET `configvalue` = ?'
- .' WHERE `appid` = ? AND `configkey` = ?' );
- $query->execute( array( $value, $app, $key ));
+ } else {
+ $oldValue = self::getValue($app, $key);
+ if($oldValue !== strval($value)) {
+ $query = OC_DB::prepare( 'UPDATE `*PREFIX*appconfig` SET `configvalue` = ?'
+ .' WHERE `appid` = ? AND `configkey` = ?' );
+ $query->execute( array( $value, $app, $key ));
+ }
}
// TODO where should this be documented?
\OC_Hook::emit('OC_Appconfig', 'post_set_value', array(
diff --git a/lib/private/preferences.php b/lib/private/preferences.php
index 359d9a8..f7fe315 100644
--- a/lib/private/preferences.php
+++ b/lib/private/preferences.php
@@ -144,10 +144,15 @@ class Preferences {
*/
public function setValue( $user, $app, $key, $value ) {
// Check if the key does exist
- $query = 'SELECT COUNT(*) FROM `*PREFIX*preferences`'
+ $query = 'SELECT `configvalue` FROM `*PREFIX*preferences`'
.' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?';
- $count = $this->conn->fetchColumn( $query, array( $user, $app, $key ));
- $exists = $count > 0;
+ $oldValue = $this->conn->fetchColumn( $query, array( $user, $app, $key ));
+ $exists = $oldValue !== false;
+
+ if($oldValue === strval($value)) {
+ // no changes
+ return true;
+ }
if( !$exists ) {
$data = array(
diff --git a/tests/lib/preferences.php b/tests/lib/preferences.php
index 68b794e..35bdd59 100644
--- a/tests/lib/preferences.php
+++ b/tests/lib/preferences.php
@@ -201,10 +201,10 @@ class Test_Preferences_Object extends PHPUnit_Framework_TestCase {
$connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
$connectionMock->expects($this->exactly(2))
->method('fetchColumn')
- ->with($this->equalTo('SELECT COUNT(*) FROM `*PREFIX*preferences`'
+ ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences`'
.' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'),
$this->equalTo(array('grg', 'bar', 'foo')))
- ->will($this->onConsecutiveCalls(0, 1));
+ ->will($this->onConsecutiveCalls(false, 'v1'));
$connectionMock->expects($this->once())
->method('insert')
->with($this->equalTo('*PREFIX*preferences'),
@@ -236,6 +236,74 @@ class Test_Preferences_Object extends PHPUnit_Framework_TestCase {
$preferences->setValue('grg', 'bar', 'foo', 'v2');
}
+ public function testSetValueUnchanged() {
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->exactly(3))
+ ->method('fetchColumn')
+ ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences`'
+ .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'),
+ $this->equalTo(array('grg', 'bar', 'foo')))
+ ->will($this->onConsecutiveCalls(false, 'v1', 'v1'));
+ $connectionMock->expects($this->once())
+ ->method('insert')
+ ->with($this->equalTo('*PREFIX*preferences'),
+ $this->equalTo(
+ array(
+ 'userid' => 'grg',
+ 'appid' => 'bar',
+ 'configkey' => 'foo',
+ 'configvalue' => 'v1',
+ )
+ ));
+ $connectionMock->expects($this->never())
+ ->method('update');
+
+ $preferences = new OC\Preferences($connectionMock);
+ $preferences->setValue('grg', 'bar', 'foo', 'v1');
+ $preferences->setValue('grg', 'bar', 'foo', 'v1');
+ $preferences->setValue('grg', 'bar', 'foo', 'v1');
+ }
+
+ public function testSetValueUnchanged2() {
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->exactly(3))
+ ->method('fetchColumn')
+ ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences`'
+ .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'),
+ $this->equalTo(array('grg', 'bar', 'foo')))
+ ->will($this->onConsecutiveCalls(false, 'v1', 'v2'));
+ $connectionMock->expects($this->once())
+ ->method('insert')
+ ->with($this->equalTo('*PREFIX*preferences'),
+ $this->equalTo(
+ array(
+ 'userid' => 'grg',
+ 'appid' => 'bar',
+ 'configkey' => 'foo',
+ 'configvalue' => 'v1',
+ )
+ ));
+ $connectionMock->expects($this->once())
+ ->method('update')
+ ->with($this->equalTo('*PREFIX*preferences'),
+ $this->equalTo(
+ array(
+ 'configvalue' => 'v2',
+ )),
+ $this->equalTo(
+ array(
+ 'userid' => 'grg',
+ 'appid' => 'bar',
+ 'configkey' => 'foo',
+ )
+ ));
+
+ $preferences = new OC\Preferences($connectionMock);
+ $preferences->setValue('grg', 'bar', 'foo', 'v1');
+ $preferences->setValue('grg', 'bar', 'foo', 'v2');
+ $preferences->setValue('grg', 'bar', 'foo', 'v2');
+ }
+
public function testDeleteKey()
{
$connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list