Skip to content

Commit

Permalink
Finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteStash committed Jan 10, 2025
1 parent 968a9fd commit 474266a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jmoiron/sqlx"
)

var appSchemaVersion uint = 47
var appSchemaVersion uint = 48

var databaseProviders map[string]databaseProvider

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE notification_type ADD VALUE 'FINGERPRINTED_SCENE_EDIT';
55 changes: 37 additions & 18 deletions pkg/sqlx/querybuilder_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,43 @@ func (qb *notificationsQueryBuilder) TriggerSceneEditNotifications(editID uuid.U
args = append(args, editID)
query := `
INSERT INTO notifications
SELECT N.user_id, N.type, $1
FROM edits E JOIN studio_favorites SF ON (E.data->'new_data'->>'studio_id')::uuid = SF.studio_id
JOIN user_notifications N ON SF.user_id = N.user_id AND N.type = 'FAVORITE_STUDIO_EDIT' AND N.user_id != E.user_id
WHERE E.id = $1
UNION
SELECT N.user_id, N.type, $1
FROM (
SELECT id, (jsonb_array_elements(edits.data->'new_data'->'added_performers')->>'performer_id')::uuid AS performer_id, user_id
FROM edits
) E JOIN performer_favorites PF ON E.performer_id = PF.performer_id
JOIN user_notifications N ON PF.user_id = N.user_id AND N.type = 'FAVORITE_PERFORMER_EDIT' AND N.user_id != E.user_id
WHERE E.id = $1
UNION
SELECT N.user_id, N.type, $1
FROM edits E
JOIN scene_fingerprints SF ON E.id = SF.edit_id
JOIN user_notifications N ON SF.user_id = N.user_id AND N.type = 'FINGERPRINTED_SCENE_EDIT' AND N.user_id != E.user_id
WHERE E.id = $1
SELECT DISTINCT ON (user_id) user_id, type, $1 FROM (
SELECT N.user_id, N.type
FROM edits E JOIN studio_favorites SF ON (E.data->'new_data'->>'studio_id')::uuid = SF.studio_id
JOIN user_notifications N ON SF.user_id = N.user_id AND N.type = 'FAVORITE_STUDIO_EDIT' AND N.user_id != E.user_id
WHERE E.id = $1
UNION
SELECT N.user_id, N.type
FROM edits E
JOIN scene_edits SE ON E.id = SE.edit_id
JOIN scenes S ON SE.scene_id = S.id
JOIN studio_favorites SF ON S.studio_id = SF.studio_id
JOIN user_notifications N ON SF.user_id = N.user_id AND N.type = 'FAVORITE_STUDIO_EDIT' AND N.user_id != E.user_id
WHERE E.id = $1
UNION
SELECT N.user_id, N.type
FROM (
SELECT id, (jsonb_array_elements(edits.data->'new_data'->'added_performers')->>'performer_id')::uuid AS performer_id, user_id
FROM edits
) E JOIN performer_favorites PF ON E.performer_id = PF.performer_id
JOIN user_notifications N ON PF.user_id = N.user_id AND N.type = 'FAVORITE_PERFORMER_EDIT' AND N.user_id != E.user_id
WHERE E.id = $1
UNION
SELECT N.user_id, N.type
FROM edits E
JOIN scene_edits SE ON E.id = SE.edit_id
JOIN scene_performers SP ON SP.scene_id = SE.scene_id
JOIN performer_favorites PF ON PF.performer_id = SP.performer_id
JOIN user_notifications N ON PF.user_id = N.user_id AND N.type = 'FAVORITE_PERFORMER_EDIT' AND N.user_id != E.user_id
WHERE E.id = $1
UNION
SELECT N.user_id, N.type
FROM edits E
JOIN scene_edits SE ON E.id = SE.edit_id
JOIN scene_fingerprints SF ON SE.scene_id = SF.scene_id
JOIN user_notifications N ON SF.user_id = N.user_id AND N.type = 'FINGERPRINTED_SCENE_EDIT' AND N.user_id != E.user_id
WHERE E.id = $1
) notifications
`
err := qb.dbi.RawExec(query, args)
return err
Expand Down

0 comments on commit 474266a

Please sign in to comment.