-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-13843] Optimize collectioncipher readbyuserid (#4916)
* Optimise stored procedure Collectioncipher_ReadByUserId * Optimise stored procedure Collectioncipher_ReadByUserId * Optimise stored procedure Collectioncipher_ReadByUserId
- Loading branch information
Showing
2 changed files
with
60 additions
and
11 deletions.
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
39 changes: 39 additions & 0 deletions
39
util/Migrator/DbScripts/2024-10-18-00_CollectionCipher_ReadByUserId.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,39 @@ | ||
CREATE OR ALTER PROCEDURE [dbo].[CollectionCipher_ReadByUserId] | ||
@UserId UNIQUEIDENTIFIER | ||
AS | ||
BEGIN | ||
SET NOCOUNT ON | ||
|
||
SELECT | ||
CC.* | ||
FROM | ||
[dbo].[CollectionCipher] CC | ||
INNER JOIN | ||
[dbo].[Collection] S ON S.[Id] = CC.[CollectionId] | ||
INNER JOIN | ||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = S.[OrganizationId] AND OU.[UserId] = @UserId | ||
INNER JOIN | ||
[dbo].[CollectionUser] CU ON CU.[CollectionId] = S.[Id] AND CU.[OrganizationUserId] = OU.[Id] | ||
WHERE | ||
OU.[Status] = 2 | ||
|
||
UNION ALL | ||
|
||
SELECT | ||
CC.* | ||
FROM | ||
[dbo].[CollectionCipher] CC | ||
INNER JOIN | ||
[dbo].[Collection] S ON S.[Id] = CC.[CollectionId] | ||
INNER JOIN | ||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = S.[OrganizationId] AND OU.[UserId] = @UserId | ||
INNER JOIN | ||
[dbo].[GroupUser] GU ON GU.[OrganizationUserId] = OU.[Id] | ||
INNER JOIN | ||
[dbo].[CollectionGroup] CG ON CG.[CollectionId] = CC.[CollectionId] AND CG.[GroupId] = GU.[GroupId] | ||
LEFT JOIN | ||
[dbo].[CollectionUser] CU ON CU.[CollectionId] = S.[Id] AND CU.[OrganizationUserId] = OU.[Id] | ||
WHERE | ||
OU.[Status] = 2 | ||
AND CU.[CollectionId] IS NULL | ||
END |