1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 21:18:13 -05:00

database tuning

This commit is contained in:
Kyle Spearrin 2018-07-28 21:25:25 -04:00
parent 407455562c
commit 98fc54881b
4 changed files with 72 additions and 8 deletions

View File

@ -32,13 +32,11 @@ BEGIN
LEFT JOIN
[dbo].[User] U ON U.[Id] = OU.[UserId]
WHERE
CU.[CollectionId] IS NOT NULL
OR CG.[CollectionId] IS NOT NULL
OR (
OU.[OrganizationId] = @OrganizationId
AND (
OU.[AccessAll] = 1
OR G.[AccessAll] = 1
)
OU.[OrganizationId] = @OrganizationId
AND (
CU.[CollectionId] IS NOT NULL
OR CG.[CollectionId] IS NOT NULL
OR OU.[AccessAll] = 1
OR G.[AccessAll] = 1
)
END

View File

@ -21,3 +21,8 @@ CREATE NONCLUSTERED INDEX [IX_OrganizationUser_UserIdOrganizationIdStatus]
ON [dbo].[OrganizationUser]([UserId] ASC, [OrganizationId] ASC, [Status] ASC)
INCLUDE ([AccessAll]);
GO
CREATE NONCLUSTERED INDEX [IX_OrganizationUser_OrganizationId]
ON [dbo].[OrganizationUser]([OrganizationId] ASC);

View File

@ -0,0 +1,59 @@
IF NOT EXISTS (
SELECT * FROM sys.indexes WHERE [Name]='IX_OrganizationUser_OrganizationId'
AND object_id = OBJECT_ID('[dbo].[OrganizationUser]')
)
BEGIN
CREATE NONCLUSTERED INDEX [IX_OrganizationUser_OrganizationId]
ON [dbo].[OrganizationUser]([OrganizationId] ASC)
END
GO
IF OBJECT_ID('[dbo].[CollectionUserDetails_ReadByCollectionId]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[CollectionUserDetails_ReadByCollectionId]
END
GO
CREATE PROCEDURE [dbo].[CollectionUserDetails_ReadByCollectionId]
@CollectionId UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT
OU.[Id] AS [OrganizationUserId],
CASE
WHEN OU.[AccessAll] = 1 OR G.[AccessAll] = 1 THEN 1
ELSE 0
END [AccessAll],
U.[Name],
ISNULL(U.[Email], OU.[Email]) Email,
OU.[Status],
OU.[Type],
CASE
WHEN OU.[AccessAll] = 1 OR CU.[ReadOnly] = 0 OR G.[AccessAll] = 1 OR CG.[ReadOnly] = 0 THEN 0
ELSE 1
END [ReadOnly]
FROM
[dbo].[OrganizationUser] OU
LEFT JOIN
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId
LEFT JOIN
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id]
LEFT JOIN
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
LEFT JOIN
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId
LEFT JOIN
[dbo].[User] U ON U.[Id] = OU.[UserId]
WHERE
OU.[OrganizationId] = @OrganizationId
AND (
CU.[CollectionId] IS NOT NULL
OR CG.[CollectionId] IS NOT NULL
OR OU.[AccessAll] = 1
OR G.[AccessAll] = 1
)
END
GO

View File

@ -11,9 +11,11 @@
<None Remove="DbScripts\2018-04-02_00_Org2fa.sql" />
<None Remove="DbScripts\2018-04-24_00_CipherQueryTuning.sql" />
<None Remove="DbScripts\2018-06-11_00_WebVaultUpdates.sql" />
<None Remove="DbScripts\2018-07-28_00_DbTuning.sql" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="DbScripts\2018-07-28_00_DbTuning.sql" />
<EmbeddedResource Include="DbScripts\2018-06-11_00_WebVaultUpdates.sql" />
<EmbeddedResource Include="DbScripts\2018-04-24_00_CipherQueryTuning.sql" />
<EmbeddedResource Include="DbScripts\2018-04-02_00_Org2fa.sql" />