From 0c930607f0444fef11e2fb7d5c50eadd905cccc7 Mon Sep 17 00:00:00 2001 From: cweiske Date: Tue, 16 Feb 2010 21:50:49 +0000 Subject: do not return numbers < 0 git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@652 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 0ac1855..3ea5b5c 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -916,9 +916,10 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db); } - $output = $this->db->sql_fetchfield(0, 0) - 1; + $count = $this->db->sql_fetchfield(0, 0); + $count = ($count > 0) ? $count - 1 : (int)$count; $this->db->sql_freeresult($dbresult); - return $output; + return $count; } -- cgit v1.2.3-54-g00ecf From 7f2e3472174354bd3f23875bdbe23914f89269dd Mon Sep 17 00:00:00 2001 From: cweiske Date: Tue, 16 Feb 2010 21:52:45 +0000 Subject: do not return numbers < 0 git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@653 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 3ea5b5c..c4d198d 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -911,7 +911,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $privacy = ' AND B.bStatus = 0'; } - $sql = 'SELECT COUNT(*) FROM '. $userservice->getTableName() .' AS U, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE U.'. $userservice->getFieldName('primary') .' = B.uId AND B.bHash = "'. md5($address) .'"'. $privacy; + $sql = 'SELECT COUNT(*) as "0" FROM '. $userservice->getTableName() .' AS U, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE U.'. $userservice->getFieldName('primary') .' = B.uId AND B.bHash = "'. md5($address) .'"'. $privacy; if (!($dbresult = & $this->db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db); } -- cgit v1.2.3-54-g00ecf From 91da444e762bd2676e94a19d45401d2e83858202 Mon Sep 17 00:00:00 2001 From: cweiske Date: Tue, 16 Feb 2010 21:59:39 +0000 Subject: reformat countOthers() git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@658 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 46 +++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index c4d198d..05ea060 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -889,31 +889,51 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService - function countOthers($address) + /** + * Counts the number of bookmarks that have the same address + * as the given address + * + * @param string $address Address/URL to look for + * + * @return integer Number of bookmarks minus one that have the address + */ + public function countOthers($address) { if (!$address) { return false; } - $userservice = SemanticScuttle_Service_Factory :: get('User'); - $sId = $userservice->getCurrentUserId(); + $us = SemanticScuttle_Service_Factory::get('User'); + $sId = (int)$us->getCurrentUserId(); - if ($userservice->isLoggedOn()) { - // All public bookmarks, user's own bookmarks and any shared with user - $privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')'; - $watchnames = $userservice->getWatchNames($sId, true); - foreach($watchnames as $watchuser) { - $privacy .= ' OR (U.username = "'. $watchuser .'" AND B.bStatus = 1)'; + if ($us->isLoggedOn()) { + //All public bookmarks, user's own bookmarks + // and any shared with our user + $privacy = ' AND ((B.bStatus = 0) OR (B.uId = ' . $sId . ')'; + $watchnames = $us->getWatchNames($sId, true); + foreach ($watchnames as $watchuser) { + $privacy .= ' OR (U.username = "' + . $this->db->sql_escape($watchuser) + . '" AND B.bStatus = 1)'; } $privacy .= ')'; } else { - // Just public bookmarks + //Just public bookmarks $privacy = ' AND B.bStatus = 0'; } - $sql = 'SELECT COUNT(*) as "0" FROM '. $userservice->getTableName() .' AS U, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE U.'. $userservice->getFieldName('primary') .' = B.uId AND B.bHash = "'. md5($address) .'"'. $privacy; - if (!($dbresult = & $this->db->sql_query($sql))) { - message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db); + $sql = 'SELECT COUNT(*) as "0" FROM ' + . $us->getTableName() . ' AS U' + . ', '. $GLOBALS['tableprefix'] . 'bookmarks AS B' + . ' WHERE U.'. $us->getFieldName('primary') .' = B.uId' + . ' AND B.bHash = "'. md5($address) . '"' + . $privacy; + + if (!($dbresult = $this->db->sql_query($sql))) { + message_die( + GENERAL_ERROR, 'Could not get other count', + '', __LINE__, __FILE__, $sql, $this->db + ); } $count = $this->db->sql_fetchfield(0, 0); -- cgit v1.2.3-54-g00ecf From 6b7217daf298be65347205aa7a0fee17ff37b87c Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:03:20 +0000 Subject: make countOthers() accept an array of addresses git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@659 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 57 +++++++++++++++++------ tests/BookmarkTest.php | 80 ++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 13 deletions(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 05ea060..c7bfb3b 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -891,17 +891,29 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService /** * Counts the number of bookmarks that have the same address - * as the given address - * - * @param string $address Address/URL to look for - * - * @return integer Number of bookmarks minus one that have the address + * as the given address. + * + * @internal + * We do support fetching counts for multiple addresses at once + * because that allows us to reduce the number of queries + * we need in the web interface when displaying i.e. + * 10 bookmarks - only one SQL query is needed then. + * + * @param string|array $addresses Address/URL to look for, string + * of one address or array with + * multiple ones + * + * @return integer Number of bookmarks minus one that have the address. + * In case $addresses was an array, key-value array + * with key being the address, value said number of + * bookmarks */ - public function countOthers($address) + public function countOthers($addresses) { - if (!$address) { + if (!$addresses) { return false; } + $bArray = is_array($addresses); $us = SemanticScuttle_Service_Factory::get('User'); $sId = (int)$us->getCurrentUserId(); @@ -922,12 +934,22 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $privacy = ' AND B.bStatus = 0'; } - $sql = 'SELECT COUNT(*) as "0" FROM ' + $addressesSql = ' AND (0'; + foreach ((array)$addresses as $address) { + $addressesSql .= ' OR B.bHash = "' + . $this->db->sql_escape(md5($address)) + . '"'; + } + $addressesSql .= ')'; + + + $sql = 'SELECT B.bAddress, COUNT(*) as count FROM ' . $us->getTableName() . ' AS U' . ', '. $GLOBALS['tableprefix'] . 'bookmarks AS B' . ' WHERE U.'. $us->getFieldName('primary') .' = B.uId' - . ' AND B.bHash = "'. md5($address) . '"' - . $privacy; + . $addressesSql + . $privacy + . ' GROUP BY B.bHash'; if (!($dbresult = $this->db->sql_query($sql))) { message_die( @@ -936,10 +958,19 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService ); } - $count = $this->db->sql_fetchfield(0, 0); - $count = ($count > 0) ? $count - 1 : (int)$count; + //be sure we also list urls in our array + // that are not found in the database + $counts = array_combine( + (array)$addresses, + array_fill(0, count((array)$addresses), 0) + ); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $counts[$row['bAddress']] + = $row['count'] > 0 ? $row['count'] - 1 : 0; + } $this->db->sql_freeresult($dbresult); - return $count; + + return $bArray ? $counts : reset($counts); } diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index d791b9e..69e6e8a 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -943,6 +943,86 @@ class BookmarkTest extends TestBase + /** + * Test what countOther() returns when multiple addresses are + * passed to it and none of them exists. + * + * @return void + */ + public function testCountOthersArrayNone() + { + $this->assertEquals( + array('1' => 0, '2' => 0, '3' => 0), + $this->bs->countOthers(array('1', '2', '3')) + ); + } + + + + /** + * Test what countOther() returns when multiple addresses are + * passed to it and only one of them exists. + * + * @return void + */ + public function testCountOthersArrayOneNone() + { + $uid = $this->addUser(); + $uid2 = $this->addUser(); + $address1 = 'http://example.org/1'; + $address2 = 'http://example.org/2'; + $this->addBookmark($uid, $address1); + $this->addBookmark($uid, $address2); + $this->addBookmark($uid2, $address1); + $this->assertEquals( + array( + $address1 => 1, + $address2 => 0 + ), + $this->bs->countOthers( + array($address1, $address2) + ) + ); + } + + + + /** + * Test what countOther() returns when multiple addresses are passed + * to it and both of them exist with different numbers for each. + * + * @return void + */ + public function testCountOthersArrayTwoOne() + { + $uid = $this->addUser(); + $uid2 = $this->addUser(); + $uid3 = $this->addUser(); + + $address1 = 'http://example.org/1'; + $address2 = 'http://example.org/2'; + + $this->addBookmark($uid, $address1); + $this->addBookmark($uid, $address2); + + $this->addBookmark($uid2, $address1); + $this->addBookmark($uid2, $address2); + + $this->addBookmark($uid3, $address1); + + $this->assertEquals( + array( + $address1 => 2, + $address2 => 1 + ), + $this->bs->countOthers( + array($address1, $address2) + ) + ); + } + + + } -- cgit v1.2.3-54-g00ecf From c4b8719b5b0b61d5fc4c7c4691f23d6635ef8f4d Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:12:51 +0000 Subject: reformat and CS git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@666 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark2Tag.php | 30 ++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index 8e5cb22..e0f831e 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -266,21 +266,39 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService return true; } - function &getTagsForBookmark($bookmarkid) { + + /** + * Retrieves all tags for a given bookmark except system tags. + * + * @param integer $bookmarkid ID of the bookmark + * + * @return array Array of tags + */ + public function getTagsForBookmark($bookmarkid) + { if (!is_numeric($bookmarkid)) { - message_die(GENERAL_ERROR, 'Could not get tags (invalid bookmarkid)', '', __LINE__, __FILE__, $query); + message_die( + GENERAL_ERROR, 'Could not get tags (invalid bookmarkid)', + '', __LINE__, __FILE__, $query + ); return false; } - $query = 'SELECT tag FROM '. $this->getTableName() .' WHERE bId = '. intval($bookmarkid) .' AND LEFT(tag, 7) <> "system:" ORDER BY id ASC'; + $query = 'SELECT tag FROM ' . $this->getTableName() + . ' WHERE bId = ' . intval($bookmarkid) + . ' AND LEFT(tag, 7) <> "system:"' + . ' ORDER BY id ASC'; - if (!($dbresult =& $this->db->sql_query($query))) { - message_die(GENERAL_ERROR, 'Could not get tags', '', __LINE__, __FILE__, $query, $this->db); + if (!($dbresult = $this->db->sql_query($query))) { + message_die( + GENERAL_ERROR, 'Could not get tags', + '', __LINE__, __FILE__, $query, $this->db + ); return false; } $tags = array(); - while ($row =& $this->db->sql_fetchrow($dbresult)) { + while ($row = $this->db->sql_fetchrow($dbresult)) { $tags[] = $row['tag']; } $this->db->sql_freeresult($dbresult); -- cgit v1.2.3-54-g00ecf From 3e9c2cd0a57d798bb7cbcf89575cbc0199e0d2e5 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:14:39 +0000 Subject: add new method for better sql performance: Bookmark2Tag::getTagsForBookmarks() git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@667 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark2Tag.php | 48 ++++++++++++++++++ tests/Bookmark2TagTest.php | 73 ++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index e0f831e..770b1d9 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -305,6 +305,54 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService return $tags; } + + /** + * Retrieves all tags for an array of bookmark IDs + * + * @param array $bookmarkids Array of bookmark IDs + * + * @return array Array of tag arrays. Key is bookmark ID. + */ + public function getTagsForBookmarks($bookmarkids) + { + if (!is_array($bookmarkids)) { + message_die( + GENERAL_ERROR, 'Could not get tags (invalid bookmarkids)', + '', __LINE__, __FILE__, $query + ); + return false; + } + + $sql = ''; + foreach ($bookmarkids as $bookmarkid) { + $sql .= ' OR bId = ' . intval($bookmarkid); + } + + $query = 'SELECT tag, bId FROM ' . $this->getTableName() + . ' WHERE (1' . $sql . ')' + . ' AND LEFT(tag, 7) <> "system:"' + . ' ORDER BY id, bId ASC'; + + if (!($dbresult = $this->db->sql_query($query))) { + message_die( + GENERAL_ERROR, 'Could not get tags', + '', __LINE__, __FILE__, $query, $this->db + ); + return false; + } + + $tags = array_combine( + $bookmarkids, + array_fill(0, count($bookmarkids), array()) + ); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $tags[$row['bId']][] = $row['tag']; + } + $this->db->sql_freeresult($dbresult); + return $tags; + } + + function &getTags($userid = NULL) { $userservice =SemanticScuttle_Service_Factory::get('User'); $logged_on_user = $userservice->getCurrentUserId(); diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index d75afd8..0afaaf8 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -126,6 +126,79 @@ class Bookmark2TagTest extends TestBase $this->assertContains('bar', $tags); $this->assertContains('fuu', $tags); } + + + + /** + * Test getTagsForBookmarks() when no bookmarks have tags. + * + * @return void + */ + public function testGetTagsForBookmarksNone() + { + $bid1 = $this->addBookmark(null, null, 0, array()); + $bid2 = $this->addBookmark(null, null, 0, array()); + + $alltags = $this->b2ts->getTagsForBookmarks( + array($bid1, $bid2) + ); + $this->assertType('array', $alltags); + $this->assertEquals(2, count($alltags)); + $this->assertType('array', $alltags[$bid1]); + $this->assertType('array', $alltags[$bid2]); + $this->assertEquals(0, count($alltags[$bid1])); + $this->assertEquals(0, count($alltags[$bid2])); + } + + + + /** + * Test getTagsForBookmarks() when most bookmarks have tags. + * + * @return void + */ + public function testGetTagsForBookmarksMost() + { + $bid1 = $this->addBookmark(null, null, 0, array()); + $this->b2ts->attachTags($bid1, array('foo', 'bar', 'fuu')); + + $bid2 = $this->addBookmark(null, null, 0, array()); + $this->b2ts->attachTags($bid2, array('foo', 'bar2', 'fuu2')); + + $bid3 = $this->addBookmark(null, null, 0, array()); + $this->b2ts->attachTags($bid3, array('foo', 'bar2', 'fuu3')); + + $bid4 = $this->addBookmark(null, null, 0, array()); + //no tags + + $alltags = $this->b2ts->getTagsForBookmarks( + array($bid1, $bid2, $bid3, $bid4) + ); + $this->assertType('array', $alltags); + foreach ($alltags as $bid => $btags) { + $this->assertType('array', $btags); + if ($bid == $bid1) { + $this->assertEquals(3, count($btags)); + $this->assertContains('foo', $btags); + $this->assertContains('bar', $btags); + $this->assertContains('fuu', $btags); + } else if ($bid == $bid2) { + $this->assertEquals(3, count($btags)); + $this->assertContains('foo', $btags); + $this->assertContains('bar2', $btags); + $this->assertContains('fuu2', $btags); + } else if ($bid == $bid3) { + $this->assertEquals(3, count($btags)); + $this->assertContains('foo', $btags); + $this->assertContains('bar2', $btags); + $this->assertContains('fuu3', $btags); + } else if ($bid == $bid4) { + $this->assertEquals(0, count($btags)); + } else { + $this->assertTrue(false, 'Unknown bookmark id'); + } + } + } } if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') { -- cgit v1.2.3-54-g00ecf From 6a6cba1a4d61d42bd93fb385f576d299bd99cc59 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:16:34 +0000 Subject: sql optimization: fetch all tags at once git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@668 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 15 +++++++++++---- src/SemanticScuttle/Service/Bookmark2Tag.php | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index c7bfb3b..9d72023 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -804,10 +804,17 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $total = $row['total']; $this->db->sql_freeresult($totalresult); - $bookmarks = array(); - while ($row = & $this->db->sql_fetchrow($dbresult)) { - $row['tags'] = $b2tservice->getTagsForBookmark(intval($row['bId'])); - $bookmarks[] = $row; + $bookmarks = array(); + $bookmarkids = array(); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $bookmarks[] = $row; + $bookmarkids[] = $row['bId']; + } + if (count($bookmarkids)) { + $tags = $b2tservice->getTagsForBookmarks($bookmarkids); + foreach ($bookmarks as &$bookmark) { + $bookmark['tags'] = $tags[$bookmark['bId']]; + } } $this->db->sql_freeresult($dbresult); diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index 770b1d9..d6c0e58 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -321,6 +321,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService '', __LINE__, __FILE__, $query ); return false; + } else if (count($bookmarkids) == 0) { + return array(); } $sql = ''; -- cgit v1.2.3-54-g00ecf From 6c9542f24b630f60490949f4e77bcb0cf1bf7377 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:18:49 +0000 Subject: make isAdmin accept a user name, too git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@669 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/User.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php index cedde92..0b28663 100644 --- a/src/SemanticScuttle/Service/User.php +++ b/src/SemanticScuttle/Service/User.php @@ -305,9 +305,14 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService /** * Checks if the given user is an administrator. * Uses global admin_users property containing admin - * user names + * user names. * - * @param integer|array $user User ID or user row from DB + * Passing the user id makes this function load the user + * from database. For efficiency reasons, try to pass + * the user name or database row. + * + * @param integer|array|string $user User ID or user row from DB + * or user name * * @return boolean True if the user is admin */ @@ -315,10 +320,13 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService { if (is_numeric($user)) { $user = $this->getUser($user); + $user = $user['username']; + } else if (is_array($user)) { + $user = $user['username']; } if (isset($GLOBALS['admin_users']) - && in_array($user['username'], $GLOBALS['admin_users']) + && in_array($user, $GLOBALS['admin_users']) ) { return true; } else { -- cgit v1.2.3-54-g00ecf From 01c792a78969dcfa3e9dd99a4491ccb6836ca8c1 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:23:07 +0000 Subject: new config option to disable "SET NAMES UTF8" sql call git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@671 b3834d28-1941-0410-a4f8-b48e95affb8f --- data/config.default.php | 9 +++++++++ doc/ChangeLog | 7 +++++++ src/SemanticScuttle/Service/Factory.php | 6 ++++-- 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'src/SemanticScuttle/Service') diff --git a/data/config.default.php b/data/config.default.php index 1b040c0..fdbdaee 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -180,6 +180,15 @@ $dbname = 'scuttle'; */ $tableprefix = 'sc_'; +/* + * If the database needs to be switched to UTF8 + * manually or not. If true, a "SET NAMES UTF8" query + * will be sent at the beginning. If you need performance, + * save this query and set it in your mysql server options. + * + * @var boolean + */ +$dbneedssetnames = true; /*************************************************** diff --git a/doc/ChangeLog b/doc/ChangeLog index c797f56..05757ac 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,10 +1,17 @@ ChangeLog for SemantiScuttle ============================ +0.97.0 - 2010-????? +------------------- +- Many SQL optimizations +- New config option to skip "SET NAMES UTF8" call: $dbneedssetnames + + 0.96.1 - 2010-02-09 ------------------- - Fix bug #2948410: API is broken in 0.96.0 + 0.96.0 - 2010-02-08 ------------------- - Fix bug #2843523: ArtViper thumbnail license change diff --git a/src/SemanticScuttle/Service/Factory.php b/src/SemanticScuttle/Service/Factory.php index 9b79e6c..d7ff1d4 100644 --- a/src/SemanticScuttle/Service/Factory.php +++ b/src/SemanticScuttle/Service/Factory.php @@ -113,7 +113,7 @@ class SemanticScuttle_Service_Factory protected static function loadDb() { global $dbhost, $dbuser, $dbpass, $dbname, - $dbport, $dbpersist, $dbtype; + $dbport, $dbpersist, $dbtype, $dbneedssetnames; if (self::$db !== null) { return; @@ -130,7 +130,9 @@ class SemanticScuttle_Service_Factory self::$db ); } - $db->sql_query('SET NAMES UTF8'); + + $dbneedssetnames && $db->sql_query('SET NAMES UTF8'); + self::$db = $db; } -- cgit v1.2.3-54-g00ecf From 35058ddd07266a70611b055b7e66c4cdd13d47e7 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:29:31 +0000 Subject: reformat _getuser and add docblock git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@675 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/User.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php index 0b28663..7b03dd2 100644 --- a/src/SemanticScuttle/Service/User.php +++ b/src/SemanticScuttle/Service/User.php @@ -76,15 +76,28 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService $this->updateSessionStability(); } - function _getuser($fieldname, $value) { - $query = 'SELECT * FROM '. $this->getTableName() .' WHERE '. $fieldname .' = "'. $this->db->sql_escape($value) .'"'; + /** + * Fetches the desired user row from database, specified by column and value + * + * @param string $fieldname Name of database column to identify user + * @param string $value Value of $fieldname + * + * @return array Database row or boolean false + */ + protected function _getuser($fieldname, $value) + { + $query = 'SELECT * FROM '. $this->getTableName() + . ' WHERE ' . $fieldname . ' = "' . $this->db->sql_escape($value) . '"'; - if (! ($dbresult =& $this->db->sql_query($query)) ) { - message_die(GENERAL_ERROR, 'Could not get user', '', __LINE__, __FILE__, $query, $this->db); + if (!($dbresult = $this->db->sql_query($query)) ) { + message_die( + GENERAL_ERROR, 'Could not get user', + '', __LINE__, __FILE__, $query, $this->db + ); return false; } - $row =& $this->db->sql_fetchrow($dbresult); + $row = $this->db->sql_fetchrow($dbresult); $this->db->sql_freeresult($dbresult); if ($row) { return $row; -- cgit v1.2.3-54-g00ecf From 41a29f49ee4446b1e743356a837a96ca29118f78 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:33:11 +0000 Subject: save another query git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@677 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 9d72023..37a6a5e 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -284,7 +284,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService } $userservice = SemanticScuttle_Service_Factory::get('User'); - $user = $userservice->getCurrentUser(); + $user = $userservice->getCurrentObjectUser(); //user has to be either admin, or owner if ($GLOBALS['adminsCanModifyBookmarksFromOtherUsers'] @@ -292,7 +292,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService ) { return true; } else { - return ($bookmark['uId'] == $user['uId']); + return ($bookmark['uId'] == $user->id); } } -- cgit v1.2.3-54-g00ecf From cae9f4de38376974b805dab6b7a95105dc61dfd9 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:35:16 +0000 Subject: fix tests after last commit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@678 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 5 ++++- src/SemanticScuttle/Service/User.php | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 37a6a5e..87d9e02 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -285,10 +285,13 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $userservice = SemanticScuttle_Service_Factory::get('User'); $user = $userservice->getCurrentObjectUser(); + if ($user === null) { + return false; + } //user has to be either admin, or owner if ($GLOBALS['adminsCanModifyBookmarksFromOtherUsers'] - && $userservice->isAdmin($user) + && $userservice->isAdmin($user->id) ) { return true; } else { diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php index 7b03dd2..281c18c 100644 --- a/src/SemanticScuttle/Service/User.php +++ b/src/SemanticScuttle/Service/User.php @@ -407,6 +407,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService } //reload user object $this->getCurrentUser(true); + $this->getCurrentObjectUser(true); } -- cgit v1.2.3-54-g00ecf From 6a2f1f4f573613400479d427c32b083a7274158b Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:37:03 +0000 Subject: reformat query git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@679 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 87d9e02..10b0b8b 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -325,7 +325,9 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $crit['uId'] = $uid; } - $sql = 'SELECT COUNT(*) as "0" FROM '. $GLOBALS['tableprefix'] .'bookmarks WHERE '. $this->db->sql_build_array('SELECT', $crit); + $sql = 'SELECT COUNT(*) as "0" FROM ' + . $GLOBALS['tableprefix'] . 'bookmarks' + . ' WHERE '. $this->db->sql_build_array('SELECT', $crit); if (!($dbresult = $this->db->sql_query($sql))) { message_die( -- cgit v1.2.3-54-g00ecf From 17374001b8ccfe806851862c91b29671ba998828 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:39:03 +0000 Subject: add SemanticScuttle_Service_Bookmark::bookmarksExist() method to check for existance of multiple bookmarks at once for future sql optimization git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@680 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 56 +++++++++++++- tests/BookmarkTest.php | 122 +++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 1 deletion(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 10b0b8b..a1bb1a5 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -312,7 +312,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService * @return boolean True when the bookmark with the given URL * exists for the user, false if not. */ - function bookmarkExists($address = false, $uid = null) + public function bookmarkExists($address = false, $uid = null) { if (!$address) { return false; @@ -346,6 +346,60 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService + /** + * Checks if the given addresses exist + * + * @param array $addresses Array of addresses + * @param integer $uid User ID the addresses shall belong to + * + * @return array Array with addresses as keys, true/false for existence + * as value + */ + public function bookmarksExist($addresses, $uid = null) + { + if (count($addresses) == 0) { + return array(); + } + + $hashes = array(); + $sql = '(1'; + foreach ($addresses as $key => $address) { + $hash = md5($this->normalize($address)); + $hashes[$hash] = $address; + $sql .= ' OR bHash = "' + . $this->db->sql_escape($hash) + . '"'; + } + $sql .= ')'; + if ($uid !== null) { + $sql .= ' AND uId = ' . intval($uid); + } + + $sql = 'SELECT bHash, COUNT(*) as "count" FROM ' + . $this->getTableName() + . ' WHERE ' . $sql + . ' GROUP BY bHash'; + + if (!($dbresult = $this->db->sql_query($sql))) { + message_die( + GENERAL_ERROR, 'Could not get bookmark counts', '', + __LINE__, __FILE__, $sql, $this->db + ); + } + + $existence = array_combine( + $addresses, + array_fill(0, count($addresses), false) + ); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $existence[$hashes[$row['bHash']]] = $row['count'] > 0; + } + + return $existence; + } + + + /** * Adds a bookmark to the database. * diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index 39a9974..74685c4 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -252,6 +252,128 @@ class BookmarkTest extends TestBase + /** + * Tests if bookmarksExist() returns true when a bookmark + * exists + * + * @return void + */ + public function testBookmarksExistTrueSingle() + { + $bid = $this->addBookmark(); + $bookmark = $this->bs->getBookmark($bid); + + $ret = $this->bs->bookmarksExist(array($bookmark['bAddress'])); + $this->assertType('array', $ret); + $this->assertEquals(1, count($ret)); + $this->assertTrue($ret[$bookmark['bAddress']]); + } + + + + /** + * Tests if bookmarksExist() returns true when all bookmarks + * exist + * + * @return void + */ + public function testBookmarksExistTrueMultiple() + { + $bid = $this->addBookmark(); + $bookmark = $this->bs->getBookmark($bid); + + $bid2 = $this->addBookmark(); + $bookmark2 = $this->bs->getBookmark($bid2); + + + $ret = $this->bs->bookmarksExist( + array( + $bookmark['bAddress'], + $bookmark2['bAddress'] + ) + ); + $this->assertType('array', $ret); + $this->assertEquals(2, count($ret)); + $this->assertTrue($ret[$bookmark['bAddress']]); + $this->assertTrue($ret[$bookmark2['bAddress']]); + } + + + + /** + * Tests if bookmarksExist() returns false when a bookmark + * does not exist + * + * @return void + */ + public function testBookmarksExistFalseSingle() + { + $ret = $this->bs->bookmarksExist(array('does-not-exist')); + $this->assertType('array', $ret); + $this->assertEquals(1, count($ret)); + $this->assertFalse($ret['does-not-exist']); + } + + + + /** + * Tests if bookmarksExist() returns false when all bookmarks + * do not exist + * + * @return void + */ + public function testBookmarksExistFalseMultiple() + { + $bms = array( + 'does-not-exist', + 'does-not-exist-2', + 'does-not-exist-3', + ); + $ret = $this->bs->bookmarksExist($bms); + $this->assertType('array', $ret); + $this->assertEquals(3, count($ret)); + $this->assertFalse($ret['does-not-exist']); + $this->assertFalse($ret['does-not-exist-2']); + $this->assertFalse($ret['does-not-exist-3']); + } + + + + /** + * Tests if bookmarksExist() returns true when some bookmarks + * exist. + * + * @return void + */ + public function testBookmarksExistSome() + { + $bid = $this->addBookmark(); + $bookmark = $this->bs->getBookmark($bid); + + $bid2 = $this->addBookmark(); + $bookmark2 = $this->bs->getBookmark($bid2); + + + $ret = $this->bs->bookmarksExist( + array( + $bookmark['bAddress'], + 'does-not-exist', + $bookmark2['bAddress'], + 'does-not-exist-2', + 'does-not-exist-3' + ) + ); + $this->assertType('array', $ret); + $this->assertEquals(5, count($ret)); + $this->assertTrue($ret[$bookmark['bAddress']]); + $this->assertTrue($ret[$bookmark2['bAddress']]); + $this->assertFalse($ret['does-not-exist']); + $this->assertFalse($ret['does-not-exist-2']); + $this->assertFalse($ret['does-not-exist-3']); + } + + + /** * Test if countBookmarks() works with no bookmarks * -- cgit v1.2.3-54-g00ecf From e993e994bb42637edc92bc139ac695a1d6458e67 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:42:44 +0000 Subject: re-fix isAdmin() sql optimization git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@682 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index a1bb1a5..88a9055 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -291,7 +291,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService //user has to be either admin, or owner if ($GLOBALS['adminsCanModifyBookmarksFromOtherUsers'] - && $userservice->isAdmin($user->id) + && $userservice->isAdmin($user->username) ) { return true; } else { -- cgit v1.2.3-54-g00ecf From 5a93096431eebb4cb458351ce5f8d1b836328ca0 Mon Sep 17 00:00:00 2001 From: cweiske Date: Wed, 17 Mar 2010 20:07:04 +0000 Subject: fix bug #2953732 and make corresponding test work. git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@688 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 88a9055..3cdec72 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -178,7 +178,8 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService */ public function getBookmarkByAddress($address) { - $hash = md5($address); + $address = $this->normalize($address); + $hash = md5($address); return $this->getBookmarkByHash($hash); } -- cgit v1.2.3-54-g00ecf From 602ec95bbb91400b6ef2647df55e83e68f4223b5 Mon Sep 17 00:00:00 2001 From: cweiske Date: Thu, 18 Mar 2010 19:24:21 +0000 Subject: unify hashing code in a separate method git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@692 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 65 ++++++++++++++++++++------------ www/bookmarks.php | 2 +- 2 files changed, 42 insertions(+), 25 deletions(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 3cdec72..2258625 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -178,9 +178,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService */ public function getBookmarkByAddress($address) { - $address = $this->normalize($address); - $hash = md5($address); - return $this->getBookmarkByHash($hash); + return $this->getBookmarkByHash($this->getHash($address)); } @@ -189,10 +187,12 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService * Retrieves a bookmark with the given hash. * DOES NOT RESPECT PRIVACY SETTINGS! * - * @param string $hash URL hash (MD5) + * @param string $hash URL hash * * @return mixed Array with bookmark data or false in case * of an error (i.e. not found). + * + * @see getHash() */ public function getBookmarkByHash($hash) { @@ -201,6 +201,25 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService + /** + * Returns the hash value of a given address. + * + * @param string $address URL to hash + * @param boolean $bNormalize If the address shall be normalized before + * being hashed + * + * @return string Hash value + */ + public function getHash($address, $bNormalize = true) + { + if ($bNormalize) { + $address = $this->normalize($address); + } + return md5($address); + } + + + /** * Retrieves a bookmark that has a given short * name. @@ -319,9 +338,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService return false; } - $address = $this->normalize($address); - - $crit = array('bHash' => md5($address)); + $crit = array('bHash' => $this->getHash($address)); if (isset ($uid)) { $crit['uId'] = $uid; } @@ -365,7 +382,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $hashes = array(); $sql = '(1'; foreach ($addresses as $key => $address) { - $hash = md5($this->normalize($address)); + $hash = $this->getHash($address); $hashes[$hash] = $address; $sql .= ' OR bHash = "' . $this->db->sql_escape($hash) @@ -462,17 +479,17 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService // Set up the SQL insert statement and execute it. $values = array( - 'uId' => intval($sId), - 'bIp' => $ip, - 'bDatetime' => $datetime, - 'bModified' => $datetime, - 'bTitle' => $title, - 'bAddress' => $address, + 'uId' => intval($sId), + 'bIp' => $ip, + 'bDatetime' => $datetime, + 'bModified' => $datetime, + 'bTitle' => $title, + 'bAddress' => $address, 'bDescription' => $description, 'bPrivateNote' => $privateNote, - 'bStatus' => intval($status), - 'bHash' => md5($address), - 'bShort' => $short + 'bStatus' => intval($status), + 'bHash' => $this->getHash($address), + 'bShort' => $short ); $sql = 'INSERT INTO '. $this->getTableName() @@ -582,14 +599,14 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService // Set up the SQL update statement and execute it. $updates = array( - 'bModified' => $moddatetime, - 'bTitle' => $title, - 'bAddress' => $address, + 'bModified' => $moddatetime, + 'bTitle' => $title, + 'bAddress' => $address, 'bDescription' => $description, 'bPrivateNote' => $privateNote, - 'bStatus' => $status, - 'bHash' => md5($address), - 'bShort' => $short + 'bStatus' => $status, + 'bHash' => $this->getHash($address, false), + 'bShort' => $short ); if (!is_null($date)) { @@ -1004,7 +1021,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $addressesSql = ' AND (0'; foreach ((array)$addresses as $address) { $addressesSql .= ' OR B.bHash = "' - . $this->db->sql_escape(md5($address)) + . $this->db->sql_escape($this->getHash($address)) . '"'; } $addressesSql .= ')'; diff --git a/www/bookmarks.php b/www/bookmarks.php index 0c9bfa4..5241481 100644 --- a/www/bookmarks.php +++ b/www/bookmarks.php @@ -167,7 +167,7 @@ if ($userservice->isLoggedOn() && POST_SUBMITTED != '') { if (GET_ACTION == "add") { // If the bookmark exists already, edit the original if ($bookmarkservice->bookmarkExists(stripslashes(GET_ADDRESS), $currentUserID)) { - $bookmark =& $bookmarkservice->getBookmarks(0, NULL, $currentUserID, NULL, NULL, NULL, NULL, NULL, NULL, md5($bookmarkservice->normalize(stripslashes(GET_ADDRESS)))); + $bookmark =& $bookmarkservice->getBookmarks(0, NULL, $currentUserID, NULL, NULL, NULL, NULL, NULL, NULL, $bookmarkservice->getHash(stripslashes(GET_ADDRESS))); $popup = (GET_POPUP!='') ? '?popup=1' : ''; header('Location: '. createURL('edit', $bookmark['bookmarks'][0]['bId'] . $popup)); exit(); -- cgit v1.2.3-54-g00ecf From d249a8ad19514e0c386391ae37081445ee6c23c7 Mon Sep 17 00:00:00 2001 From: cweiske Date: Thu, 18 Mar 2010 19:26:09 +0000 Subject: fix bad bug that was introduced due to performance optimizations git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@693 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SemanticScuttle/Service') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 2258625..364b1a0 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -380,7 +380,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService } $hashes = array(); - $sql = '(1'; + $sql = '(0'; foreach ($addresses as $key => $address) { $hash = $this->getHash($address); $hashes[$hash] = $address; -- cgit v1.2.3-54-g00ecf From 31570df64ce6543de407e7b9d751ba9033d930de Mon Sep 17 00:00:00 2001 From: cweiske Date: Fri, 9 Jul 2010 10:04:35 +0000 Subject: Fix bug getTagsForBookmarks() that fetched all tags, see http://sourceforge.net/projects/semanticscuttle/forums/forum/759510/topic/3752670 for details git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@715 b3834d28-1941-0410-a4f8-b48e95affb8f --- doc/ChangeLog | 5 +++++ src/SemanticScuttle/Service/Bookmark2Tag.php | 7 +------ tests/Bookmark2TagTest.php | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/SemanticScuttle/Service') diff --git a/doc/ChangeLog b/doc/ChangeLog index 5b4e4d3..5e24f07 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,6 +1,11 @@ ChangeLog for SemantiScuttle ============================ +0.9X.X - 2010-XX-XX +------------------- +- Fix bug getTagsForBookmarks() that fetched all tags + + 0.97.0 - 2010-06-09 ------------------- - Many SQL optimizations - SemanticScuttle shows bookmarks 4 times faster now diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index d6c0e58..4d2c969 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -325,13 +325,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService return array(); } - $sql = ''; - foreach ($bookmarkids as $bookmarkid) { - $sql .= ' OR bId = ' . intval($bookmarkid); - } - $query = 'SELECT tag, bId FROM ' . $this->getTableName() - . ' WHERE (1' . $sql . ')' + . ' WHERE bId IN (' . implode(',', $bookmarkids) . ')' . ' AND LEFT(tag, 7) <> "system:"' . ' ORDER BY id, bId ASC'; diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index 0afaaf8..14b71cc 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -171,6 +171,12 @@ class Bookmark2TagTest extends TestBase $bid4 = $this->addBookmark(null, null, 0, array()); //no tags + //bookmark that does not get queried + //http://sourceforge.net/projects/semanticscuttle/forums/forum/759510/topic/3752670 + $bid5 = $this->addBookmark(null, null, 0, array()); + $this->b2ts->attachTags($bid5, array('foo', 'bar2', 'fuu5')); + + $alltags = $this->b2ts->getTagsForBookmarks( array($bid1, $bid2, $bid3, $bid4) ); -- cgit v1.2.3-54-g00ecf