From f4a5e034b3881cf3e16cd60607db06cd8f201539 Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Tue, 9 Aug 2022 14:55:36 +0100 Subject: [PATCH] LibraryPanels: Rewrite invalid connection deletion query to be MySQL-friendly (#53460) Closes #53456 --- pkg/services/libraryelements/database.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/services/libraryelements/database.go b/pkg/services/libraryelements/database.go index 86e1ed7d6c0..80ab0141dd3 100644 --- a/pkg/services/libraryelements/database.go +++ b/pkg/services/libraryelements/database.go @@ -28,7 +28,12 @@ SELECT DISTINCT , (SELECT COUNT(connection_id) FROM ` + models.LibraryElementConnectionTableName + ` WHERE element_id = le.id AND kind=1) AS connected_dashboards` ) -const deleteInvalidConnections = "DELETE FROM library_element_connection WHERE connection_id IN (SELECT connection_id as id FROM library_element_connection WHERE element_id=? EXCEPT SELECT id from dashboard)" +const deleteInvalidConnections = ` +DELETE FROM library_element_connection +WHERE connection_id IN ( + SELECT connection_id as id FROM library_element_connection + WHERE element_id=? AND connection_id NOT IN (SELECT id as connection_id from dashboard) +)` func getFromLibraryElementDTOWithMeta(dialect migrator.Dialect) string { user := dialect.Quote("user") @@ -591,7 +596,7 @@ func (l *LibraryElementService) getConnections(c context.Context, signedInUser * return connections, err } -//getElementsForDashboardID gets all elements for a specific dashboard +// getElementsForDashboardID gets all elements for a specific dashboard func (l *LibraryElementService) getElementsForDashboardID(c context.Context, dashboardID int64) (map[string]LibraryElementDTO, error) { libraryElementMap := make(map[string]LibraryElementDTO) err := l.SQLStore.WithDbSession(c, func(session *sqlstore.DBSession) error {