mirror of
https://github.com/Radarr/Radarr.git
synced 2024-08-18 00:09:37 +02:00
parent
d008768fff
commit
41492efd2e
@ -14,34 +14,32 @@ public CleanupAbsolutePathMetadataFiles(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
using var mapper = _database.OpenConnection();
|
||||
if (_database.DatabaseType == DatabaseType.PostgreSQL)
|
||||
{
|
||||
if (_database.DatabaseType == DatabaseType.PostgreSQL)
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" = ANY (
|
||||
SELECT ""Id"" FROM ""MetadataFiles""
|
||||
WHERE ""RelativePath""
|
||||
LIKE '_:\\%'
|
||||
OR ""RelativePath""
|
||||
LIKE '\\%'
|
||||
OR ""RelativePath""
|
||||
LIKE '/%'
|
||||
)");
|
||||
}
|
||||
else
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""Id"" FROM ""MetadataFiles""
|
||||
WHERE ""RelativePath""
|
||||
LIKE '_:\%'
|
||||
OR ""RelativePath""
|
||||
LIKE '\%'
|
||||
OR ""RelativePath""
|
||||
LIKE '/%'
|
||||
)");
|
||||
}
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" = ANY (
|
||||
SELECT ""Id"" FROM ""MetadataFiles""
|
||||
WHERE ""RelativePath""
|
||||
LIKE '_:\\%'
|
||||
OR ""RelativePath""
|
||||
LIKE '\\%'
|
||||
OR ""RelativePath""
|
||||
LIKE '/%'
|
||||
)");
|
||||
}
|
||||
else
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""Id"" FROM ""MetadataFiles""
|
||||
WHERE ""RelativePath""
|
||||
LIKE '_:\%'
|
||||
OR ""RelativePath""
|
||||
LIKE '\%'
|
||||
OR ""RelativePath""
|
||||
LIKE '/%'
|
||||
)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,11 @@ public CleanupAdditionalNamingSpecs(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""NamingConfig""
|
||||
WHERE ""Id"" NOT IN (
|
||||
SELECT ""Id"" FROM ""NamingConfig""
|
||||
LIMIT 1)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""NamingConfig""
|
||||
WHERE ""Id"" NOT IN (
|
||||
SELECT ""Id"" FROM ""NamingConfig""
|
||||
LIMIT 1)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,11 @@ public CleanupAdditionalUsers(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""Users""
|
||||
WHERE ""Id"" NOT IN (
|
||||
SELECT ""Id"" FROM ""Users""
|
||||
LIMIT 1)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""Users""
|
||||
WHERE ""Id"" NOT IN (
|
||||
SELECT ""Id"" FROM ""Users""
|
||||
LIMIT 1)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,30 +16,28 @@ public CleanupDownloadClientUnavailablePendingReleases(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
using var mapper = _database.OpenConnection();
|
||||
if (_database.DatabaseType == DatabaseType.PostgreSQL)
|
||||
{
|
||||
if (_database.DatabaseType == DatabaseType.PostgreSQL)
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""PendingReleases""
|
||||
mapper.Execute(@"DELETE FROM ""PendingReleases""
|
||||
WHERE ""Added"" < @TwoWeeksAgo
|
||||
AND ""Reason"" = ANY (@Reasons)",
|
||||
new
|
||||
{
|
||||
TwoWeeksAgo = DateTime.UtcNow.AddDays(-14),
|
||||
Reasons = new[] { (int)PendingReleaseReason.DownloadClientUnavailable, (int)PendingReleaseReason.Fallback }
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
new
|
||||
{
|
||||
TwoWeeksAgo = DateTime.UtcNow.AddDays(-14),
|
||||
Reasons = new[] { (int)PendingReleaseReason.DownloadClientUnavailable, (int)PendingReleaseReason.Fallback }
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""PendingReleases""
|
||||
WHERE ""Added"" < @TwoWeeksAgo
|
||||
AND ""REASON"" IN @Reasons",
|
||||
new
|
||||
{
|
||||
TwoWeeksAgo = DateTime.UtcNow.AddDays(-14),
|
||||
Reasons = new[] { (int)PendingReleaseReason.DownloadClientUnavailable, (int)PendingReleaseReason.Fallback }
|
||||
});
|
||||
}
|
||||
new
|
||||
{
|
||||
TwoWeeksAgo = DateTime.UtcNow.AddDays(-14),
|
||||
Reasons = new[] { (int)PendingReleaseReason.DownloadClientUnavailable, (int)PendingReleaseReason.Fallback }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,30 +20,26 @@ public void Clean()
|
||||
|
||||
private void DeleteDuplicateMovieMetadata()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT MIN(""Id"") FROM ""MetadataFiles""
|
||||
WHERE ""Type"" = 1
|
||||
GROUP BY ""MovieId"", ""Consumer""
|
||||
HAVING COUNT(""MovieId"") > 1
|
||||
)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT MIN(""Id"") FROM ""MetadataFiles""
|
||||
WHERE ""Type"" = 1
|
||||
GROUP BY ""MovieId"", ""Consumer""
|
||||
HAVING COUNT(""MovieId"") > 1
|
||||
)");
|
||||
}
|
||||
|
||||
private void DeleteDuplicateMovieFileMetadata()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT MIN(""Id"") FROM ""MetadataFiles""
|
||||
WHERE ""Type"" = 1
|
||||
GROUP BY ""MovieFileId"", ""Consumer""
|
||||
HAVING COUNT(""MovieFileId"") > 1
|
||||
)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT MIN(""Id"") FROM ""MetadataFiles""
|
||||
WHERE ""Type"" = 1
|
||||
GROUP BY ""MovieFileId"", ""Consumer""
|
||||
HAVING COUNT(""MovieFileId"") > 1
|
||||
)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,13 @@ public CleanupOrphanedAlternativeTitles(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""AlternativeTitles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""AlternativeTitles"".""Id"" FROM ""AlternativeTitles""
|
||||
LEFT OUTER JOIN ""MovieMetadata""
|
||||
ON ""AlternativeTitles"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
WHERE ""MovieMetadata"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""AlternativeTitles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""AlternativeTitles"".""Id"" FROM ""AlternativeTitles""
|
||||
LEFT OUTER JOIN ""MovieMetadata""
|
||||
ON ""AlternativeTitles"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
WHERE ""MovieMetadata"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,13 @@ public CleanupOrphanedBlocklist(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""Blocklist""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""Blocklist"".""Id"" FROM ""Blocklist""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""Blocklist"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""Blocklist""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""Blocklist"".""Id"" FROM ""Blocklist""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""Blocklist"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,11 @@ public CleanupOrphanedCollections(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""Collections"" WHERE ""TmdbId"" IN (SELECT ""X"".""TmdbId"" FROM (SELECT ""Collections"".""TmdbId"", COUNT(""Movies"".""Id"") as ""MovieCount"" FROM ""Collections""
|
||||
LEFT OUTER JOIN ""MovieMetadata"" ON ""Collections"".""TmdbId"" = ""MovieMetadata"".""CollectionTmdbId""
|
||||
LEFT OUTER JOIN ""Movies"" ON ""Movies"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
GROUP BY ""Collections"".""Id"") AS ""X"" WHERE ""X"".""MovieCount"" = 0)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""Collections"" WHERE ""TmdbId"" IN (SELECT ""X"".""TmdbId"" FROM (SELECT ""Collections"".""TmdbId"", COUNT(""Movies"".""Id"") as ""MovieCount"" FROM ""Collections""
|
||||
LEFT OUTER JOIN ""MovieMetadata"" ON ""Collections"".""TmdbId"" = ""MovieMetadata"".""CollectionTmdbId""
|
||||
LEFT OUTER JOIN ""Movies"" ON ""Movies"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
GROUP BY ""Collections"".""Id"") AS ""X"" WHERE ""X"".""MovieCount"" = 0)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,13 @@ public CleanupOrphanedCredits(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""Credits""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""Credits"".""Id"" FROM ""Credits""
|
||||
LEFT OUTER JOIN ""MovieMetadata""
|
||||
ON ""Credits"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
WHERE ""MovieMetadata"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""Credits""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""Credits"".""Id"" FROM ""Credits""
|
||||
LEFT OUTER JOIN ""MovieMetadata""
|
||||
ON ""Credits"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
WHERE ""MovieMetadata"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,13 @@ public CleanupOrphanedDownloadClientStatus(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""DownloadClientStatus""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""DownloadClientStatus"".""Id"" FROM ""DownloadClientStatus""
|
||||
LEFT OUTER JOIN ""DownloadClients""
|
||||
ON ""DownloadClientStatus"".""ProviderId"" = ""DownloadClients"".""Id""
|
||||
WHERE ""DownloadClients"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""DownloadClientStatus""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""DownloadClientStatus"".""Id"" FROM ""DownloadClientStatus""
|
||||
LEFT OUTER JOIN ""DownloadClients""
|
||||
ON ""DownloadClientStatus"".""ProviderId"" = ""DownloadClients"".""Id""
|
||||
WHERE ""DownloadClients"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,29 +20,25 @@ public void Clean()
|
||||
|
||||
private void DeleteOrphanedByMovie()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""ExtraFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""ExtraFiles"".""Id"" FROM ""ExtraFiles""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""ExtraFiles"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""ExtraFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""ExtraFiles"".""Id"" FROM ""ExtraFiles""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""ExtraFiles"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
|
||||
private void DeleteOrphanedByMovieFile()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""ExtraFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""ExtraFiles"".""Id"" FROM ""ExtraFiles""
|
||||
LEFT OUTER JOIN ""MovieFiles""
|
||||
ON ""ExtraFiles"".""MovieFileId"" = ""MovieFiles"".""Id""
|
||||
WHERE ""ExtraFiles"".""MovieFileId"" > 0
|
||||
AND ""MovieFiles"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""ExtraFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""ExtraFiles"".""Id"" FROM ""ExtraFiles""
|
||||
LEFT OUTER JOIN ""MovieFiles""
|
||||
ON ""ExtraFiles"".""MovieFileId"" = ""MovieFiles"".""Id""
|
||||
WHERE ""ExtraFiles"".""MovieFileId"" > 0
|
||||
AND ""MovieFiles"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,13 @@ public void Clean()
|
||||
|
||||
private void CleanupOrphanedByMovie()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""History""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""History"".""Id"" FROM ""History""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""History"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""History""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""History"".""Id"" FROM ""History""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""History"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,13 @@ public CleanupOrphanedIndexerStatus(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""IndexerStatus""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""IndexerStatus"".""Id"" FROM ""IndexerStatus""
|
||||
LEFT OUTER JOIN ""Indexers""
|
||||
ON ""IndexerStatus"".""ProviderId"" = ""Indexers"".""Id""
|
||||
WHERE ""Indexers"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""IndexerStatus""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""IndexerStatus"".""Id"" FROM ""IndexerStatus""
|
||||
LEFT OUTER JOIN ""Indexers""
|
||||
ON ""IndexerStatus"".""ProviderId"" = ""Indexers"".""Id""
|
||||
WHERE ""Indexers"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,41 +21,35 @@ public void Clean()
|
||||
|
||||
private void DeleteOrphanedByMovie()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""MetadataFiles"".""Id"" FROM ""MetadataFiles""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""MetadataFiles"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""MetadataFiles"".""Id"" FROM ""MetadataFiles""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""MetadataFiles"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
|
||||
private void DeleteOrphanedByMovieFile()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""MetadataFiles"".""Id"" FROM ""MetadataFiles""
|
||||
LEFT OUTER JOIN ""MovieFiles""
|
||||
ON ""MetadataFiles"".""MovieFileId"" = ""MovieFiles"".""Id""
|
||||
WHERE ""MetadataFiles"".""MovieFileId"" > 0
|
||||
AND ""MovieFiles"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""MetadataFiles"".""Id"" FROM ""MetadataFiles""
|
||||
LEFT OUTER JOIN ""MovieFiles""
|
||||
ON ""MetadataFiles"".""MovieFileId"" = ""MovieFiles"".""Id""
|
||||
WHERE ""MetadataFiles"".""MovieFileId"" > 0
|
||||
AND ""MovieFiles"".""Id"" IS NULL)");
|
||||
}
|
||||
|
||||
private void DeleteWhereMovieFileIsZero()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""Id"" FROM ""MetadataFiles""
|
||||
WHERE ""Type"" IN (1, 2)
|
||||
AND ""MovieFileId"" = 0)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""MetadataFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""Id"" FROM ""MetadataFiles""
|
||||
WHERE ""Type"" IN (1, 2)
|
||||
AND ""MovieFileId"" = 0)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,13 @@ public CleanupOrphanedMovieFiles(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""MovieFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""MovieFiles"".""Id"" FROM ""MovieFiles""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""MovieFiles"".""Id"" = ""Movies"".""MovieFileId""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""MovieFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""MovieFiles"".""Id"" FROM ""MovieFiles""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""MovieFiles"".""Id"" = ""Movies"".""MovieFileId""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,16 +14,14 @@ public CleanupOrphanedMovieMetadata(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""MovieMetadata""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""MovieMetadata"".""Id"" FROM ""MovieMetadata""
|
||||
LEFT OUTER JOIN ""Movies"" ON ""Movies"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
LEFT OUTER JOIN ""Collections"" ON ""Collections"".""TmdbId"" = ""MovieMetadata"".""CollectionTmdbId""
|
||||
LEFT OUTER JOIN ""ImportListMovies"" ON ""ImportListMovies"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL AND ""ImportListMovies"".""Id"" IS NULL AND ""Collections"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""MovieMetadata""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""MovieMetadata"".""Id"" FROM ""MovieMetadata""
|
||||
LEFT OUTER JOIN ""Movies"" ON ""Movies"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
LEFT OUTER JOIN ""Collections"" ON ""Collections"".""TmdbId"" = ""MovieMetadata"".""CollectionTmdbId""
|
||||
LEFT OUTER JOIN ""ImportListMovies"" ON ""ImportListMovies"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL AND ""ImportListMovies"".""Id"" IS NULL AND ""Collections"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,16 +14,14 @@ public CleanupOrphanedMovieMovieFileIds(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"UPDATE ""Movies""
|
||||
SET ""MovieFileId"" = 0
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""Movies"".""Id"" FROM ""Movies""
|
||||
LEFT OUTER JOIN ""MovieFiles""
|
||||
ON ""Movies"".""MovieFileId"" = ""MovieFiles"".""Id""
|
||||
WHERE ""MovieFiles"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"UPDATE ""Movies""
|
||||
SET ""MovieFileId"" = 0
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""Movies"".""Id"" FROM ""Movies""
|
||||
LEFT OUTER JOIN ""MovieFiles""
|
||||
ON ""Movies"".""MovieFileId"" = ""MovieFiles"".""Id""
|
||||
WHERE ""MovieFiles"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,13 @@ public CleanupOrphanedMovieTranslations(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""MovieTranslations""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""MovieTranslations"".""Id"" FROM ""MovieTranslations""
|
||||
LEFT OUTER JOIN ""MovieMetadata""
|
||||
ON ""MovieTranslations"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
WHERE ""MovieMetadata"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""MovieTranslations""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""MovieTranslations"".""Id"" FROM ""MovieTranslations""
|
||||
LEFT OUTER JOIN ""MovieMetadata""
|
||||
ON ""MovieTranslations"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
WHERE ""MovieMetadata"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,13 @@ public CleanupOrphanedPendingReleases(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""PendingReleases""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""PendingReleases"".""Id"" FROM ""PendingReleases""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""PendingReleases"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""PendingReleases""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""PendingReleases"".""Id"" FROM ""PendingReleases""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""PendingReleases"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,29 +20,25 @@ public void Clean()
|
||||
|
||||
private void DeleteOrphanedByMovie()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""SubtitleFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""SubtitleFiles"".""Id"" FROM ""SubtitleFiles""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""SubtitleFiles"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""SubtitleFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""SubtitleFiles"".""Id"" FROM ""SubtitleFiles""
|
||||
LEFT OUTER JOIN ""Movies""
|
||||
ON ""SubtitleFiles"".""MovieId"" = ""Movies"".""Id""
|
||||
WHERE ""Movies"".""Id"" IS NULL)");
|
||||
}
|
||||
|
||||
private void DeleteOrphanedByMovieFile()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""SubtitleFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""SubtitleFiles"".""Id"" FROM ""SubtitleFiles""
|
||||
LEFT OUTER JOIN ""MovieFiles""
|
||||
ON ""SubtitleFiles"".""MovieFileId"" = ""MovieFiles"".""Id""
|
||||
WHERE ""SubtitleFiles"".""MovieFileId"" > 0
|
||||
AND ""MovieFiles"".""Id"" IS NULL)");
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"DELETE FROM ""SubtitleFiles""
|
||||
WHERE ""Id"" IN (
|
||||
SELECT ""SubtitleFiles"".""Id"" FROM ""SubtitleFiles""
|
||||
LEFT OUTER JOIN ""MovieFiles""
|
||||
ON ""SubtitleFiles"".""MovieFileId"" = ""MovieFiles"".""Id""
|
||||
WHERE ""SubtitleFiles"".""MovieFileId"" > 0
|
||||
AND ""MovieFiles"".""Id"" IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,31 +18,29 @@ public CleanupUnusedTags(IMainDatabase database)
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
using var mapper = _database.OpenConnection();
|
||||
var usedTags = new[] { "Movies", "Notifications", "DelayProfiles", "Restrictions", "ImportLists", "Indexers" }
|
||||
.SelectMany(v => GetUsedTags(v, mapper))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
if (usedTags.Any())
|
||||
{
|
||||
var usedTags = new[] { "Movies", "Notifications", "DelayProfiles", "Restrictions", "ImportLists", "Indexers" }
|
||||
.SelectMany(v => GetUsedTags(v, mapper))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
var usedTagsList = usedTags.Select(d => d.ToString()).Join(",");
|
||||
|
||||
if (usedTags.Any())
|
||||
if (_database.DatabaseType == DatabaseType.PostgreSQL)
|
||||
{
|
||||
var usedTagsList = usedTags.Select(d => d.ToString()).Join(",");
|
||||
|
||||
if (_database.DatabaseType == DatabaseType.PostgreSQL)
|
||||
{
|
||||
mapper.Execute($"DELETE FROM \"Tags\" WHERE NOT \"Id\" = ANY (\'{{{usedTagsList}}}\'::int[])");
|
||||
}
|
||||
else
|
||||
{
|
||||
mapper.Execute($"DELETE FROM \"Tags\" WHERE NOT \"Id\" IN ({usedTagsList})");
|
||||
}
|
||||
mapper.Execute($"DELETE FROM \"Tags\" WHERE NOT \"Id\" = ANY (\'{{{usedTagsList}}}\'::int[])");
|
||||
}
|
||||
else
|
||||
{
|
||||
mapper.Execute("DELETE FROM \"Tags\"");
|
||||
mapper.Execute($"DELETE FROM \"Tags\" WHERE NOT \"Id\" IN ({usedTagsList})");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mapper.Execute("DELETE FROM \"Tags\"");
|
||||
}
|
||||
}
|
||||
|
||||
private int[] GetUsedTags(string table, IDbConnection mapper)
|
||||
|
@ -24,13 +24,11 @@ public void Clean()
|
||||
_logger.Debug("Not running scheduled task last execution cleanup during debug");
|
||||
}
|
||||
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"UPDATE ""ScheduledTasks""
|
||||
SET ""LastExecution"" = @time
|
||||
WHERE ""LastExecution"" > @time",
|
||||
new { time = DateTime.UtcNow });
|
||||
}
|
||||
using var mapper = _database.OpenConnection();
|
||||
mapper.Execute(@"UPDATE ""ScheduledTasks""
|
||||
SET ""LastExecution"" = @time
|
||||
WHERE ""LastExecution"" > @time",
|
||||
new { time = DateTime.UtcNow });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user