clean peers + snatched table unique

This commit is contained in:
xiaomlove
2023-04-02 02:42:45 +08:00
parent caaf140beb
commit 4703cf7b28
7 changed files with 133 additions and 16 deletions

View File

@@ -22,6 +22,7 @@ use App\Repositories\ExamRepository;
use App\Repositories\SearchBoxRepository;
use App\Repositories\TagRepository;
use App\Repositories\ToolRepository;
use App\Repositories\TorrentRepository;
use Carbon\Carbon;
use GuzzleHttp\Client;
use Illuminate\Database\Eloquent\Model;
@@ -289,6 +290,12 @@ class Update extends Install
}
}
if (!$this->isSnatchedTableTorrentUserUnique()) {
$torrentRep = new TorrentRepository();
$torrentRep->removeDuplicateSnatch();
$this->runMigrate('database/migrations/2023_03_29_021950_handle_snatched_user_torrent_unique.php');
}
}
public function runExtraMigrate()
@@ -481,6 +488,18 @@ class Update extends Install
}
}
private function isSnatchedTableTorrentUserUnique(): bool
{
$tableName = 'snatched';
$result = NexusDB::select('show index from ' . $tableName);
foreach ($result as $item) {
if (in_array($item->Column_name, ['torrentid', 'userid']) && $item->Non_unique == 0) {
return true;
}
}
return false;
}