mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-01 13:36:29 +00:00
Select all networks to prevent delete issues
This commit is contained in:
@@ -180,36 +180,41 @@ export async function rebuildClientAssociationsFromSiteResource(
|
|||||||
|
|
||||||
/////////// process the client-siteResource associations ///////////
|
/////////// process the client-siteResource associations ///////////
|
||||||
|
|
||||||
// get all of the clients associated with other resources in the same network,
|
// get all of the clients associated with other site resources that share
|
||||||
// joined through siteNetworks so we know which siteId each client belongs to
|
// any of the same sites as this site resource (via siteNetworks). We can't
|
||||||
const allUpdatedClientsFromOtherResourcesOnThisSite = siteResource.networkId
|
// simply filter by networkId since each site resource has its own network;
|
||||||
? await trx
|
// two site resources serving the same site typically belong to different
|
||||||
.select({
|
// networks that both happen to include the site through siteNetworks.
|
||||||
clientId: clientSiteResourcesAssociationsCache.clientId,
|
const sitesListSiteIds = sitesList.map((s) => s.siteId);
|
||||||
siteId: siteNetworks.siteId
|
const allUpdatedClientsFromOtherResourcesOnThisSite =
|
||||||
})
|
sitesListSiteIds.length > 0
|
||||||
.from(clientSiteResourcesAssociationsCache)
|
? await trx
|
||||||
.innerJoin(
|
.select({
|
||||||
siteResources,
|
clientId: clientSiteResourcesAssociationsCache.clientId,
|
||||||
eq(
|
siteId: siteNetworks.siteId
|
||||||
clientSiteResourcesAssociationsCache.siteResourceId,
|
})
|
||||||
siteResources.siteResourceId
|
.from(clientSiteResourcesAssociationsCache)
|
||||||
)
|
.innerJoin(
|
||||||
)
|
siteResources,
|
||||||
.innerJoin(
|
eq(
|
||||||
siteNetworks,
|
clientSiteResourcesAssociationsCache.siteResourceId,
|
||||||
eq(siteNetworks.networkId, siteResources.networkId)
|
siteResources.siteResourceId
|
||||||
)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(siteResources.networkId, siteResource.networkId),
|
|
||||||
ne(
|
|
||||||
siteResources.siteResourceId,
|
|
||||||
siteResource.siteResourceId
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
.innerJoin(
|
||||||
: [];
|
siteNetworks,
|
||||||
|
eq(siteNetworks.networkId, siteResources.networkId)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
inArray(siteNetworks.siteId, sitesListSiteIds),
|
||||||
|
ne(
|
||||||
|
siteResources.siteResourceId,
|
||||||
|
siteResource.siteResourceId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
: [];
|
||||||
|
|
||||||
// Build a per-site map so the loop below can check by siteId rather than
|
// Build a per-site map so the loop below can check by siteId rather than
|
||||||
// across the entire network.
|
// across the entire network.
|
||||||
|
|||||||
Reference in New Issue
Block a user