-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimized notifications.getorder_includestatus and added indexes (#279)
* Optimized notifications.getorder_includestatus and added indexes * Added newline at the end of the file --------- Co-authored-by: Henning Normann <[email protected]>
- Loading branch information
1 parent
fa7d2ef
commit 3a17466
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
src/Altinn.Notifications.Persistence/Migration/v0.09/01-setup-indexes.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,4 @@ | ||
CREATE INDEX IF NOT EXISTS notifications_sendersreference_creatorname ON notifications.orders (sendersreference, creatorname); | ||
CREATE INDEX IF NOT EXISTS notifications_emailnotifications_orderid ON notifications.emailnotifications (_orderid) include (_id, result); | ||
CREATE INDEX IF NOT EXISTS notifications_emailnotifications_result ON notifications.emailnotifications (result) include (_id, _orderid); | ||
CREATE INDEX IF NOT EXISTS notifications_emailtexts_orderid ON notifications.emailtexts (_orderid); |
46 changes: 46 additions & 0 deletions
46
src/Altinn.Notifications.Persistence/Migration/v0.09/02-setup-functions.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,46 @@ | ||
DROP FUNCTION IF EXISTS notifications.getorder_includestatus(_alternateid UUID, _creatorname TEXT); | ||
CREATE OR REPLACE FUNCTION notifications.getorder_includestatus(_alternateid UUID, _creatorname TEXT) | ||
RETURNS TABLE ( | ||
alternateid UUID, | ||
creatorname TEXT, | ||
sendersreference TEXT, | ||
created TIMESTAMPTZ, | ||
requestedsendtime TIMESTAMPTZ, | ||
processed TIMESTAMPTZ, | ||
processedstatus orderprocessingstate, | ||
generatedEmailCount BIGINT, | ||
succeededEmailCount BIGINT | ||
) | ||
LANGUAGE 'plpgsql' | ||
AS $BODY$ | ||
DECLARE | ||
_target_orderid INTEGER; | ||
_succeededEmailCount BIGINT; | ||
_generatedEmailCount BIGINT; | ||
BEGIN | ||
SELECT _id INTO _target_orderid FROM notifications.orders | ||
WHERE orders.alternateid = _alternateid AND orders.creatorname = _creatorname; | ||
|
||
SELECT | ||
SUM(CASE WHEN result = 'Succeeded' THEN 1 ELSE 0 END), COUNT(1) AS generatedEmailCount | ||
INTO _succeededEmailCount, _generatedEmailCount | ||
FROM notifications.emailnotifications | ||
WHERE _orderid = _target_orderid; | ||
|
||
RETURN QUERY | ||
SELECT | ||
orders.alternateid, | ||
orders.creatorname, | ||
orders.sendersreference, | ||
orders.created, | ||
orders.requestedsendtime, | ||
orders.processed, | ||
orders.processedstatus, | ||
_generatedEmailCount, | ||
_succeededEmailCount | ||
FROM | ||
notifications.orders AS orders | ||
WHERE | ||
orders.alternateid = _alternateid; | ||
END; | ||
$BODY$; |