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

Added an index for tweet_id in the _media tables for new bins #303

Open
wants to merge 5 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
1 change: 1 addition & 0 deletions capture/common/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ function create_bin($bin_name, $dbh = false) {
`indice_start` int(11),
`indice_end` int(11),
PRIMARY KEY (`id`, `tweet_id`),
KEY `tweet_id` (`tweet_id`),
KEY `media_url_https` (`media_url_https`),
KEY `media_type` (`media_type`),
KEY `photo_size_width` (`photo_size_width`),
Expand Down
45 changes: 45 additions & 0 deletions common/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,51 @@ function upgrades($dry_run = false, $interactive = true, $aulevel = 2, $single =
}
}

// 18/02/2018 Add index for tweet_id in _media tables

$query = "SHOW TABLES";
$rec = $dbh->prepare($query);
$rec->execute();
$results = $rec->fetchAll(PDO::FETCH_COLUMN);
$ans = '';
if ($interactive == false) {
if ($aulevel >= 0) {
$ans = 'a';
} else {
$ans = 'SKIP';
}
}
if ($ans !== 'SKIP') {
foreach ($results as $k => $v) {
if (!preg_match("/_media$/", $v)) continue;
if ($single && $v !== $single . '_media') { continue; }
$query = "SHOW INDEXES FROM $v";
$rec = $dbh->prepare($query);
$rec->execute();
$indexes = $rec->fetchAll();
$update = TRUE;
foreach ($indexes as $index) {
if ($index['Key_name'] == 'tweet_id' && $index['Column_name'] == 'tweet_id') {
$update = FALSE;
break;
}
}
if ($update && $dry_run) {
$suggested = true;
}
if ($update && $dry_run == false) {
if ($ans !== 'a') {
$ans = cli_yesnoall("Add tweet_id index for table $v");
}
if ($ans == 'a' || $ans == 'y') {
logit($logtarget, "Adding index for tweet_id on table $v");
$query = "CREATE INDEX `tweet_id` ON " . quoteIdent($v) . " (`tweet_id`)";
$rec = $dbh->prepare($query);
$rec->execute();
}
}
}
}

// End of upgrades

Expand Down