Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/320743
Change subject: WIP DNM new schema ...................................................................... WIP DNM new schema Change-Id: Iad7d3b4d58fd5ceff7a1b594144a9db2ab5f4826 --- A db/addCognatePages.sql M db/addCognateTitles.sql M src/CognateHooks.php M src/CognateStore.php M tests/phpunit/CognateStoreTest.php 5 files changed, 44 insertions(+), 34 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cognate refs/changes/43/320743/1 diff --git a/db/addCognatePages.sql b/db/addCognatePages.sql new file mode 100644 index 0000000..de3341d --- /dev/null +++ b/db/addCognatePages.sql @@ -0,0 +1,8 @@ +-- Add cognate_pages table + +CREATE TABLE IF NOT EXISTS /*_*/cognate_pages ( + cgpa_site VARBINARY(32) NOT NULL, + cgpa_namespace INT NOT NULL, + cgpa_title INT NOT NULL, + PRIMARY KEY (cgpa_site, cgpa_namespace, cgpa_title) + )/*$wgDBTableOptions*/; \ No newline at end of file diff --git a/db/addCognateTitles.sql b/db/addCognateTitles.sql index e6c4ff4..3607ff0 100644 --- a/db/addCognateTitles.sql +++ b/db/addCognateTitles.sql @@ -1,11 +1,10 @@ -- Add cognate_titles table CREATE TABLE IF NOT EXISTS /*_*/cognate_titles ( - cgti_site VARBINARY(32) NOT NULL, - cgti_namespace INT NOT NULL, - cgti_title VARBINARY(255), - cgti_key VARBINARY(255) NOT NULL, - PRIMARY KEY (cgti_site, cgti_namespace, cgti_title) + cgti_id INT NOT NULL PRIMERY KEY, + cgti_text VARBINARY(255) NOT NULL, + cgti_key INT NOT NULL )/*$wgDBTableOptions*/; -CREATE INDEX /*i*/cgti_keys ON /*_*/cognate_titles (cgti_site, cgti_namespace, cgti_key); \ No newline at end of file +CREATE INDEX /*i*/cgti_keys ON /*_*/cognate_titles (cgti_key); +CREATE INDEX /*i*/cgti_texts ON /*_*/cognate_titles (cgti_text); \ No newline at end of file diff --git a/src/CognateHooks.php b/src/CognateHooks.php index 7e4a066..f1fa7e6 100644 --- a/src/CognateHooks.php +++ b/src/CognateHooks.php @@ -99,6 +99,9 @@ } $updater->addExtensionUpdate( + [ 'addTable', 'cognate_pages', __DIR__ . '/../db/addCognatePages.sql', true ] + ); + $updater->addExtensionUpdate( [ 'addTable', 'cognate_titles', __DIR__ . '/../db/addCognateTitles.sql', true ] ); $updater->addExtensionUpdate( diff --git a/src/CognateStore.php b/src/CognateStore.php index 474d932..1c2ff99 100644 --- a/src/CognateStore.php +++ b/src/CognateStore.php @@ -48,10 +48,10 @@ */ public function savePage( $languageCode, LinkTarget $linkTarget ) { $pageData = [ - 'cgti_site' => $languageCode, - 'cgti_title' => $linkTarget->getDBkey(), - 'cgti_namespace' => $linkTarget->getNamespace(), - 'cgti_key' => $this->stringNormalizer->normalize( $linkTarget->getDBkey() ), + 'cgpa_site' => $languageCode, + 'cgpa_title' => $linkTarget->getDBkey(), + 'cgpa_namespace' => $linkTarget->getNamespace(), + 'cgpa_key' => $this->stringNormalizer->normalize( $linkTarget->getDBkey() ), ]; $dbw = $this->loadBalancer->getConnectionRef( DB_MASTER, [], $this->databaseName ); $result = $dbw->insert( self::TITLES_TABLE_NAME, $pageData, __METHOD__, [ 'IGNORE' ] ); @@ -67,9 +67,9 @@ */ public function deletePage( $languageCode, LinkTarget $linkTarget ) { $pageData = [ - 'cgti_site' => $languageCode, - 'cgti_title' => $linkTarget->getDBkey(), - 'cgti_namespace' => $linkTarget->getNamespace(), + 'cgpa_site' => $languageCode, + 'cgpa_title' => $linkTarget->getDBkey(), + 'cgpa_namespace' => $linkTarget->getNamespace(), ]; $dbw = $this->loadBalancer->getConnectionRef( DB_MASTER, [], $this->databaseName ); $result = $dbw->delete( self::TITLES_TABLE_NAME, $pageData, __METHOD__ ); @@ -86,17 +86,17 @@ $dbr = $this->loadBalancer->getConnectionRef( DB_SLAVE, [], $this->databaseName ); $result = $dbr->select( self::TITLES_TABLE_NAME, - [ 'cgti_site' ], + [ 'cgpa_site' ], [ - 'cgti_site != ' . $dbr->addQuotes( $languageCode ), - 'cgti_key' => $this->stringNormalizer->normalize( $linkTarget->getDBkey() ), - 'cgti_namespace' => $linkTarget->getNamespace(), + 'cgpa_site != ' . $dbr->addQuotes( $languageCode ), + 'cgpa_key' => $this->stringNormalizer->normalize( $linkTarget->getDBkey() ), + 'cgpa_namespace' => $linkTarget->getNamespace(), ] ); $languageCodes = []; while ( $row = $result->fetchRow() ) { - $languageCodes[] = $row[ 'cgti_site' ]; + $languageCodes[] = $row[ 'cgpa_site' ]; } return $languageCodes; @@ -114,10 +114,10 @@ $toInsert = []; foreach ( $titleDetailsArray as $titleDetails ) { $toInsert[] = [ - 'cgti_site' => $titleDetails['site'], - 'cgti_namespace' => $titleDetails['namespace'], - 'cgti_title' => $titleDetails['title'], - 'cgti_key' => $this->stringNormalizer->normalize( $titleDetails['title'] ), + 'cgpa_site' => $titleDetails['site'], + 'cgpa_namespace' => $titleDetails['namespace'], + 'cgpa_title' => $titleDetails['title'], + 'cgpa_key' => $this->stringNormalizer->normalize( $titleDetails['title'] ), ]; } diff --git a/tests/phpunit/CognateStoreTest.php b/tests/phpunit/CognateStoreTest.php index 1f42d73..a395785 100644 --- a/tests/phpunit/CognateStoreTest.php +++ b/tests/phpunit/CognateStoreTest.php @@ -26,8 +26,8 @@ $this->store->savePage( 'en', new TitleValue( 0, 'My_test_page' ) ); $this->assertSelect( 'cognate_titles', - [ 'cgti_site', 'cgti_title', 'cgti_key', 'cgti_namespace' ], - [ 'cgti_title != "UTPage"' ], + [ 'cgpa_site', 'cgpa_title', 'cgpa_key', 'cgpa_namespace' ], + [ 'cgpa_title != "UTPage"' ], [ [ 'en', 'My_test_page', 'My test page', 0 ] ] ); } @@ -37,8 +37,8 @@ $this->store->savePage( 'en', new TitleValue( 0, 'My_second_test_page' ) ); $this->assertSelect( 'cognate_titles', - [ 'cgti_site', 'cgti_title', 'cgti_key', 'cgti_namespace' ], - [ 'cgti_title != "UTPage"' ], + [ 'cgpa_site', 'cgpa_title', 'cgpa_key', 'cgpa_namespace' ], + [ 'cgpa_title != "UTPage"' ], [ [ 'en', 'My_second_test_page', 'My second test page', 0 ] ] ); } @@ -57,8 +57,8 @@ $this->store->deletePage( 'en', new TitleValue( 0, 'My_test_page' ) ); $this->assertSelect( 'cognate_titles', - [ 'cgti_site', 'cgti_title', 'cgti_key', 'cgti_namespace' ], - [ 'cgti_title != "UTPage"' ], + [ 'cgpa_site', 'cgpa_title', 'cgpa_key', 'cgpa_namespace' ], + [ 'cgpa_title != "UTPage"' ], [] ); } @@ -67,8 +67,8 @@ $this->store->addTitles( [] ); $this->assertSelect( 'cognate_titles', - [ 'cgti_site', 'cgti_title', 'cgti_key', 'cgti_namespace' ], - [ 'cgti_title != "UTPage"' ], + [ 'cgpa_site', 'cgpa_title', 'cgpa_key', 'cgpa_namespace' ], + [ 'cgpa_title != "UTPage"' ], [] ); } @@ -77,8 +77,8 @@ $this->store->addTitles( [ [ 'site' => 'en', 'namespace' => 0, 'title' => 'Berlin' ] ] ); $this->assertSelect( 'cognate_titles', - [ 'cgti_site', 'cgti_title', 'cgti_key', 'cgti_namespace' ], - [ 'cgti_title != "UTPage"' ], + [ 'cgpa_site', 'cgpa_title', 'cgpa_key', 'cgpa_namespace' ], + [ 'cgpa_title != "UTPage"' ], [ [ 'en', 'Berlin', 'Berlin', '0' ] ] ); } @@ -90,8 +90,8 @@ ] ); $this->assertSelect( 'cognate_titles', - [ 'cgti_site', 'cgti_title', 'cgti_key', 'cgti_namespace' ], - [ 'cgti_title != "UTPage"' ], + [ 'cgpa_site', 'cgpa_title', 'cgpa_key', 'cgpa_namespace' ], + [ 'cgpa_title != "UTPage"' ], [ [ 'en', 'Berlin', 'Berlin', '0' ], [ 'fr', 'Foo', 'Foo', '1' ], -- To view, visit https://gerrit.wikimedia.org/r/320743 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iad7d3b4d58fd5ceff7a1b594144a9db2ab5f4826 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Cognate Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits