-
Notifications
You must be signed in to change notification settings - Fork 2
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
Improve performance #137
Improve performance #137
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,9 @@ | |
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" /> | ||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" /> | ||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.1" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security bulletin upgrade |
||
<PackageReference Include="System.Net.Http" Version="4.3.4" /> | ||
<PackageReference Include="System.Text.Json" Version="8.0.3" /> | ||
<PackageReference Include="System.Text.Json" Version="8.0.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,12 @@ | |
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="8.0.6" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="8.0.7" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" /> | ||
<PackageReference Include="System.Net.Http" Version="4.3.4" /> | ||
<PackageReference Include="System.Text.Json" Version="8.0.3" /> | ||
<PackageReference Include="System.Text.Json" Version="8.0.4" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security bulletin upgrade |
||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,26 +103,48 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) | |
modelBuilder.HasDbFunction(typeof(HSBContext) | ||
.GetMethod( | ||
nameof(FindServerHistoryItemsByMonth), | ||
new[] { typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string) })! | ||
).HasName("FindServerHistoryItemsByMonth"); | ||
|
||
[typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string)])! | ||
).HasName(nameof(FindServerHistoryItemsByMonth)); | ||
modelBuilder.HasDbFunction(typeof(HSBContext) | ||
.GetMethod( | ||
nameof(FindServerHistoryItemsByMonthForUser), | ||
new[] { typeof(int), typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string) })! | ||
).HasName("FindServerHistoryItemsByMonthForUser"); | ||
|
||
[typeof(int), typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string)])! | ||
).HasName(nameof(FindServerHistoryItemsByMonthForUser)); | ||
modelBuilder.HasDbFunction(typeof(HSBContext) | ||
.GetMethod( | ||
nameof(FindFileSystemHistoryItemsByMonth), | ||
new[] { typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string) })!) | ||
.HasName("FindFileSystemHistoryItemsByMonth"); | ||
|
||
[typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string)])! | ||
).HasName(nameof(FindFileSystemHistoryItemsByMonth)); | ||
modelBuilder.HasDbFunction(typeof(HSBContext) | ||
.GetMethod( | ||
nameof(FindFileSystemHistoryItemsByMonthForUser), | ||
new[] { typeof(int), typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string) })!) | ||
.HasName("FindFileSystemHistoryItemsByMonthForUser"); | ||
[typeof(int), typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string)])! | ||
).HasName(nameof(FindFileSystemHistoryItemsByMonthForUser)); | ||
|
||
// modelBuilder.Entity<ServerHistoryItemsByMonth>().ToTable((string?)null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Various attempts to get Entity Framework to allow mapping the stored procedures to other objects. I was unsuccessful, but hope to figure this out still. |
||
// modelBuilder.Entity<ServerHistoryItemsByMonthForUser>().ToTable((string?)null); | ||
// modelBuilder.Entity<FileSystemHistoryItemsByMonth>().ToTable((string?)null); | ||
// modelBuilder.Entity<FileSystemHistoryItemsByMonthForUser>().ToTable((string?)null); | ||
|
||
// modelBuilder.Ignore<ServerHistoryItemsByMonth>(); | ||
// modelBuilder.Ignore<ServerHistoryItemsByMonthForUser>(); | ||
// modelBuilder.Ignore<FileSystemHistoryItemsByMonth>(); | ||
// modelBuilder.Ignore<FileSystemHistoryItemsByMonthForUser>(); | ||
|
||
// modelBuilder.Entity<ServerHistoryItemSmall>().ToView("vServerHistoryItem").HasKey(m => m.Id); | ||
// modelBuilder.Entity<ServerHistoryItemsByMonthForUser>().ToView("vServerHistoryItem").HasKey(m => m.Id); | ||
// modelBuilder.Entity<FileSystemHistoryItemsByMonth>().ToView("vFileSystemHistoryItem").HasKey(m => m.Id); | ||
// modelBuilder.Entity<FileSystemHistoryItemSmall>().ToView("vFileSystemHistoryItem").HasKey(m => m.Id); | ||
|
||
// modelBuilder.Entity<ServerHistoryItemsByMonth>().HasNoKey().ToSqlQuery("SELECT * FROM public.vServerHistoryItem"); | ||
// modelBuilder.Entity<ServerHistoryItemsByMonthForUser>().HasNoKey().ToSqlQuery("SELECT * FROM public.vServerHistoryItem"); | ||
// modelBuilder.Entity<FileSystemHistoryItemsByMonth>().HasNoKey().ToSqlQuery("SELECT * FROM public.vFileSystemHistoryItem"); | ||
// modelBuilder.Entity<FileSystemHistoryItemsByMonthForUser>().HasNoKey().ToSqlQuery("SELECT * FROM public.vFileSystemHistoryItem"); | ||
|
||
// modelBuilder.Entity<ServerHistoryItemsByMonth>().ToFunction(nameof(FindServerHistoryItemsByMonth)); | ||
// modelBuilder.Entity<ServerHistoryItemsByMonthForUser>().ToFunction(nameof(FindServerHistoryItemsByMonthForUser)); | ||
// modelBuilder.Entity<FileSystemHistoryItemsByMonth>().ToFunction(nameof(FindFileSystemHistoryItemsByMonth)); | ||
// modelBuilder.Entity<FileSystemHistoryItemsByMonthForUser>().ToFunction(nameof(FindFileSystemHistoryItemsByMonthForUser)); | ||
} | ||
|
||
/// <summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
DROP FUNCTION "FindFileSystemHistoryItemsByMonth"; | ||
|
||
CREATE OR REPLACE FUNCTION "FindFileSystemHistoryItemsByMonth"( | ||
"startDate" TIMESTAMPTZ | ||
, "endDate" TIMESTAMPTZ DEFAULT NULL | ||
, "tenantId" INT DEFAULT NULL | ||
, "organizationId" INT DEFAULT NULL | ||
, "operatingSystemItemId" INT DEFAULT NULL | ||
, "serverServiceNowKey" VARCHAR(200) DEFAULT NULL | ||
) | ||
RETURNS SETOF public."FileSystemHistoryItem" | ||
LANGUAGE plpgsql | ||
AS $$ | ||
DECLARE | ||
end_date_default TIMESTAMPTZ; | ||
last_month_start TIMESTAMPTZ; | ||
BEGIN | ||
end_date_default := (SELECT COALESCE($2, NOW())); | ||
last_month_start := (SELECT (DATE_TRUNC('month', end_date_default))::TIMESTAMPTZ); | ||
RETURN QUERY | ||
SELECT DISTINCT | ||
"Id" | ||
, "ServiceNowKey" | ||
, "RawData" | ||
, "RawDataCI" | ||
, "Name" | ||
, "Label" | ||
, "Category" | ||
, "Subcategory" | ||
, "StorageType" | ||
, "MediaType" | ||
, "VolumeId" | ||
, "ClassName" | ||
, "Capacity" | ||
, "DiskSpace" | ||
, "Size" | ||
, "SizeBytes" | ||
, "UsedSizeBytes" | ||
, "AvailableSpace" | ||
, "FreeSpace" | ||
, "FreeSpaceBytes" | ||
, "CreatedOn" | ||
, "CreatedBy" | ||
, "UpdatedOn" | ||
, "UpdatedBy" | ||
, "Version" | ||
, "ServerItemServiceNowKey" | ||
, "InstallStatus" | ||
FROM ( | ||
SELECT fshi.* | ||
, ROW_NUMBER() OVER (PARTITION BY fshi."ServiceNowKey", EXTRACT(YEAR FROM fshi."CreatedOn"), EXTRACT(MONTH FROM fshi."CreatedOn") ORDER BY fshi."CreatedOn" DESC) AS "rn" | ||
FROM public."FileSystemHistoryItem" AS fshi | ||
JOIN public."FileSystemItem" AS fsi ON fshi."ServiceNowKey" = fsi."ServiceNowKey" | ||
JOIN public."ServerItem" AS si ON fsi."ServerItemServiceNowKey" = si."ServiceNowKey" | ||
WHERE fshi."CreatedOn" >= $1 | ||
AND fshi."CreatedOn" < last_month_start | ||
AND ($3 IS NULL OR si."TenantId" = $3) | ||
AND ($4 IS NULL OR si."OrganizationId" = $4) | ||
AND ($5 IS NULL OR si."OperatingSystemItemId" = $5) | ||
AND ($6 IS NULL OR fshi."ServerItemServiceNowKey" = $6) | ||
UNION | ||
SELECT fshi.* | ||
, ROW_NUMBER() OVER (PARTITION BY fshi."ServiceNowKey", EXTRACT(YEAR FROM fshi."CreatedOn"), EXTRACT(MONTH FROM fshi."CreatedOn") ORDER BY fshi."CreatedOn" DESC) AS "rn" | ||
FROM public."FileSystemHistoryItem" AS fshi | ||
JOIN public."FileSystemItem" AS fsi ON fshi."ServiceNowKey" = fsi."ServiceNowKey" | ||
JOIN public."ServerItem" AS si ON fsi."ServerItemServiceNowKey" = si."ServiceNowKey" | ||
WHERE fshi."InstallStatus" = 1 | ||
AND fshi."CreatedOn" >= last_month_start | ||
AND ($2 IS NULL OR fshi."CreatedOn" <= $2) | ||
AND ($3 IS NULL OR si."TenantId" = $3) | ||
AND ($4 IS NULL OR si."OrganizationId" = $4) | ||
AND ($5 IS NULL OR si."OperatingSystemItemId" = $5) | ||
AND ($6 IS NULL OR fshi."ServerItemServiceNowKey" = $6) | ||
) AS "sub" | ||
WHERE "rn" = 1 | ||
ORDER BY "ServiceNowKey", "CreatedOn"; | ||
END;$$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed local build/debug