Use a combined unique index

This commit is contained in:
Michael 2020-12-02 00:34:10 +00:00
parent 425440ec24
commit b2dadf0f92
4 changed files with 9 additions and 9 deletions

View file

@ -470,7 +470,7 @@ CREATE TABLE IF NOT EXISTS `delayed-post` (
`uid` mediumint unsigned COMMENT 'Owner User id',
`delayed` datetime COMMENT 'delay time',
PRIMARY KEY(`id`),
UNIQUE INDEX `uri` (`uri`(190)),
UNIQUE INDEX `uid_uri` (`uid`,`uri`(190)),
FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Posts that are about to be posted at a later time';

View file

@ -42,7 +42,7 @@ class Delayed
*/
public static function add(string $delayed, array $item, int $notify = 0, array $taglist = [], array $attachments = [])
{
if (empty($item['uri']) || empty($item['uid']) || self::exists($item['uri'])) {
if (empty($item['uri']) || empty($item['uid']) || self::exists($item['uri'], $item['uid'])) {
return false;
}
@ -59,9 +59,9 @@ class Delayed
*
* @return bool delete success
*/
private static function delete(string $uri)
private static function delete(string $uri, int $uid)
{
return DBA::delete('delayed-post', ['uri' => $uri]);
return DBA::delete('delayed-post', ['uri' => $uri, 'uid' => $uid]);
}
/**
@ -71,9 +71,9 @@ class Delayed
*
* @return bool "true" if an entry with that URI exists
*/
public static function exists(string $uri)
public static function exists(string $uri, int $uid)
{
return DBA::exists('delayed-post', ['uri' => $uri]);
return DBA::exists('delayed-post', ['uri' => $uri, 'uid' => $uid]);
}
/**
@ -93,7 +93,7 @@ class Delayed
// It should always contain an URI since this is needed to create a delayed post entry
if (!empty($item['uri'])) {
$result = self::delete($item['uri']);
$result = self::delete($item['uri'], $item['uid']);
Logger::notice('Delayed post entry deleted', ['result' => $result, 'uri' => $item['uri']]);
}

View file

@ -615,7 +615,7 @@ class Feed
}
$condition = ['uid' => $item['uid'], 'uri' => $item['uri']];
if (!Item::exists($condition) && !Post\Delayed::exists($item["uri"])) {
if (!Item::exists($condition) && !Post\Delayed::exists($item["uri"], $item['uid'])) {
$postings[] = ['item' => $item, 'notify' => $notify,
'taglist' => $taglist, 'attachments' => $attachments];
} else {

View file

@ -537,7 +537,7 @@ return [
],
"indexes" => [
"PRIMARY" => ["id"],
"uri" => ["UNIQUE", "uri(190)"],
"uid_uri" => ["UNIQUE", "uid", "uri(190)"],
]
],
"diaspora-interaction" => [