forked from Kentico/KInspector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ExternalStorageLimitationAnalysis Kentico#224
- Loading branch information
1 parent
518ef96
commit 26223f4
Showing
9 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/KInspector.Reports/ExternalStorageLimitationAnalysis/Metadata/en-US.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
details: | ||
name: External storage limitation analysis | ||
shortDescription: Checks whether media libraries are following recommendations for external storage. | ||
longDescription: | | ||
Web sites utilizing external storage (Azure Blob or Amazon S3) should limit media library folder size to a maximum 100 items per folder. If you exceed the limit, alter the structure that allows you to divide the files into multiple folders. | ||
See [Media library limitations when storing files in an external storage](https://docs.kentico.com/13/configuring-xperience/configuring-the-environment-for-content-editors/configuring-media-libraries#media-library-limitations-when-storing-files-in-an-external-storage). | ||
terms: | ||
summaries: | ||
good: No issues found. | ||
error: <totalFolders> <totalFolders|folder|folders> with excessive media files. | ||
tableTitles: | ||
tablesOverLimit: Folders with more than 100 files |
13 changes: 13 additions & 0 deletions
13
src/KInspector.Reports/ExternalStorageLimitationAnalysis/Models/CmsMediaFolderResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace KInspector.Reports.ExternalStorageLimitationAnalysis.Models | ||
{ | ||
public class CmsMediaFolderResult | ||
{ | ||
public string? LibraryDisplayName { get; set; } | ||
|
||
public string? FolderName { get; set; } | ||
|
||
public string? SiteName { get; set; } | ||
|
||
public int NumberOfFiles { get; set; } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/KInspector.Reports/ExternalStorageLimitationAnalysis/Models/Terms.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using KInspector.Core.Models; | ||
|
||
namespace KInspector.Reports.ExternalStorageLimitationAnalysis.Models | ||
{ | ||
public class Terms | ||
{ | ||
public Summaries? Summaries { get; set; } | ||
|
||
public TableTitles? TableTitles { get; set; } | ||
} | ||
|
||
public class Summaries | ||
{ | ||
public Term? Good { get; set; } | ||
|
||
public Term? Error { get; set; } | ||
} | ||
|
||
public class TableTitles | ||
{ | ||
public Term? TablesOverLimit { get; set; } | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/KInspector.Reports/ExternalStorageLimitationAnalysis/Report.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using KInspector.Core; | ||
using KInspector.Core.Constants; | ||
using KInspector.Core.Helpers; | ||
using KInspector.Core.Models; | ||
using KInspector.Core.Services.Interfaces; | ||
using KInspector.Reports.ExternalStorageLimitationAnalysis.Models; | ||
|
||
namespace KInspector.Reports.ExternalStorageLimitationAnalysis | ||
{ | ||
public class Report : AbstractReport<Terms> | ||
{ | ||
private readonly IDatabaseService databaseService; | ||
|
||
public Report(IDatabaseService databaseService, IModuleMetadataService moduleMetadataService) : base(moduleMetadataService) | ||
{ | ||
this.databaseService = databaseService; | ||
} | ||
|
||
public override IList<Version> CompatibleVersions => VersionHelper.GetVersionList("12", "13"); | ||
|
||
public override IList<string> Tags => new List<string> { | ||
ModuleTags.Performance, | ||
ModuleTags.Azure, | ||
ModuleTags.AmazonS3 | ||
}; | ||
|
||
public async override Task<ModuleResults> GetResults() | ||
{ | ||
var foldersOverLimit = await databaseService.ExecuteSqlFromFile<CmsMediaFolderResult>(Scripts.GetMediaFoldersWithMoreThan100Files); | ||
if (foldersOverLimit.Any()) | ||
{ | ||
var result = new ModuleResults | ||
{ | ||
Status = ResultsStatus.Error, | ||
Type = ResultsType.TableList, | ||
Summary = Metadata.Terms.Summaries?.Error?.With(new { totalFolders = foldersOverLimit.Count() }) | ||
}; | ||
result.TableResults.Add(new TableResult | ||
{ | ||
Name = Metadata.Terms.TableTitles?.TablesOverLimit, | ||
Rows = foldersOverLimit | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
return new ModuleResults | ||
{ | ||
Status = ResultsStatus.Good, | ||
Type = ResultsType.NoResults, | ||
Summary = Metadata.Terms.Summaries?.Good | ||
}; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/KInspector.Reports/ExternalStorageLimitationAnalysis/Scripts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace KInspector.Reports.ExternalStorageLimitationAnalysis | ||
{ | ||
public static class Scripts | ||
{ | ||
public static string BaseDirectory => $"{nameof(ExternalStorageLimitationAnalysis)}/Scripts"; | ||
|
||
public static string GetMediaFoldersWithMoreThan100Files => $"{BaseDirectory}/{nameof(GetMediaFoldersWithMoreThan100Files)}.sql"; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...Reports/ExternalStorageLimitationAnalysis/Scripts/GetMediaFoldersWithMoreThan100Files.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- File parent folder path is used to group items | ||
-- This path is calculated from FilePath field by removing the file part | ||
-- Example: | ||
-- /somefolder/subfolder/filename.ext -> /somefolder/subfolder | ||
-- /filename.ext -> '' (empty string) | ||
|
||
SELECT LibraryDisplayName, | ||
COALESCE(NULLIF(SUBSTRING('/' + f.FilePath, 0, LEN('/' + f.FilePath) - CHARINDEX('/', REVERSE('/' + f.FilePath)) + 1), ''), '/') AS 'FolderName', | ||
SiteName, | ||
COUNT(*) AS 'NumberOfFiles' | ||
FROM Media_File AS F | ||
INNER JOIN Media_Library AS L ON F.FileLibraryID = L.LibraryID | ||
INNER JOIN CMS_Site AS S ON S.SiteID = L.LibrarySiteID | ||
GROUP BY SUBSTRING('/' + F.FilePath, 0, LEN('/' + F.FilePath) - CHARINDEX('/', REVERSE('/' + F.FilePath)) + 1), LibraryDisplayName, SiteName | ||
HAVING COUNT(*) > 100 | ||
ORDER BY LibraryDisplayName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters