Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnf_files: Make sure files_dbname and files_name has a unique index #82

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 3 additions & 28 deletions includes/jobs/GlobalNewFilesInsertJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,13 @@ public function run() {

$dbw = GlobalNewFilesHooks::getGlobalDB( DB_PRIMARY );

$exists = $dbw->selectRowCount(
$dbw->upsert(
'gnf_files',
'*',
[
'files_dbname' => WikiMap::getCurrentWikiId(),
'files_name' => $uploadedFile->getName(),
],
__METHOD__,
[ 'LIMIT' => 1 ]
);

if ( $exists ) {
$dbw->update(
'gnf_files',
[
'files_timestamp' => $dbw->timestamp(),
'files_url' => $uploadedFile->getFullUrl(),
'files_uploader' => $this->userId,
],
[
'files_dbname' => WikiMap::getCurrentWikiId(),
'files_name' => $uploadedFile->getName(),
],
__METHOD__
);

return true;
}

$dbw->insert(
'gnf_files',
[ [ 'files_dbname', 'files_name' ] ],
[
'files_dbname' => WikiMap::getCurrentWikiId(),
'files_name' => $uploadedFile->getName(),
Expand All @@ -68,8 +44,7 @@ public function run() {
'files_timestamp' => $dbw->timestamp(),
'files_url' => $uploadedFile->getFullUrl(),
'files_uploader' => $this->userId,
],
__METHOD__
]
);

return true;
Expand Down
2 changes: 2 additions & 0 deletions sql/gnf_files.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ CREATE INDEX /*i*/files_dbname ON /*_*/gnf_files (files_dbname);
CREATE INDEX /*i*/files_timestamp ON /*_*/gnf_files (files_timestamp);
CREATE INDEX /*i*/files_name ON /*_*/gnf_files (files_name);
CREATE INDEX /*i*/files_private ON /*_*/gnf_files (files_private);

CREATE UNIQUE INDEX /*i*/files_name_unique ON /*_*/gnf_files (files_dbname, files_name);
Loading