mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-04 17:56:38 +00:00
Fixing various bugs
This commit is contained in:
@@ -1086,10 +1086,8 @@ async function getDomainId(
|
|||||||
|
|
||||||
// remove the base domain of the domain
|
// remove the base domain of the domain
|
||||||
let subdomain = null;
|
let subdomain = null;
|
||||||
if (domainSelection.type == "ns" || domainSelection.type == "wildcard") {
|
if (fullDomain != baseDomain) {
|
||||||
if (fullDomain != baseDomain) {
|
subdomain = fullDomain.replace(`.${baseDomain}`, "");
|
||||||
subdomain = fullDomain.replace(`.${baseDomain}`, "");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the first valid domain
|
// Return the first valid domain
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ export async function getNextAvailableClientSubnet(
|
|||||||
orgId: string,
|
orgId: string,
|
||||||
transaction: Transaction | typeof db = db
|
transaction: Transaction | typeof db = db
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const [org] = await db.select().from(orgs).where(eq(orgs.orgId, orgId));
|
const [org] = await transaction.select().from(orgs).where(eq(orgs.orgId, orgId));
|
||||||
|
|
||||||
if (!org) {
|
if (!org) {
|
||||||
throw new Error(`Organization with ID ${orgId} not found`);
|
throw new Error(`Organization with ID ${orgId} not found`);
|
||||||
@@ -257,14 +257,14 @@ export async function getNextAvailableClientSubnet(
|
|||||||
throw new Error(`Organization with ID ${orgId} has no subnet defined`);
|
throw new Error(`Organization with ID ${orgId} has no subnet defined`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingAddressesSites = await db
|
const existingAddressesSites = await transaction
|
||||||
.select({
|
.select({
|
||||||
address: sites.address
|
address: sites.address
|
||||||
})
|
})
|
||||||
.from(sites)
|
.from(sites)
|
||||||
.where(and(isNotNull(sites.address), eq(sites.orgId, orgId)));
|
.where(and(isNotNull(sites.address), eq(sites.orgId, orgId)));
|
||||||
|
|
||||||
const existingAddressesClients = await db
|
const existingAddressesClients = await transaction
|
||||||
.select({
|
.select({
|
||||||
address: clients.subnet
|
address: clients.subnet
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -160,12 +160,20 @@ export async function updateSiteBandwidth(
|
|||||||
|
|
||||||
// Aggregate bandwidth usage for the org
|
// Aggregate bandwidth usage for the org
|
||||||
const totalBandwidth = peer.bytesIn + peer.bytesOut;
|
const totalBandwidth = peer.bytesIn + peer.bytesOut;
|
||||||
const currentOrgUsage = orgUsageMap.get(updatedSite.orgId) || 0;
|
const currentOrgUsage =
|
||||||
orgUsageMap.set(updatedSite.orgId, currentOrgUsage + totalBandwidth);
|
orgUsageMap.get(updatedSite.orgId) || 0;
|
||||||
|
orgUsageMap.set(
|
||||||
|
updatedSite.orgId,
|
||||||
|
currentOrgUsage + totalBandwidth
|
||||||
|
);
|
||||||
|
|
||||||
// Add 10 seconds of uptime for each active site
|
// Add 10 seconds of uptime for each active site
|
||||||
const currentOrgUptime = orgUptimeMap.get(updatedSite.orgId) || 0;
|
const currentOrgUptime =
|
||||||
orgUptimeMap.set(updatedSite.orgId, currentOrgUptime + 10 / 60);
|
orgUptimeMap.get(updatedSite.orgId) || 0;
|
||||||
|
orgUptimeMap.set(
|
||||||
|
updatedSite.orgId,
|
||||||
|
currentOrgUptime + 10 / 60
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(
|
||||||
@@ -181,7 +189,9 @@ export async function updateSiteBandwidth(
|
|||||||
// This separates the concerns and reduces lock contention
|
// This separates the concerns and reduces lock contention
|
||||||
if (calcUsageAndLimits && (orgUsageMap.size > 0 || orgUptimeMap.size > 0)) {
|
if (calcUsageAndLimits && (orgUsageMap.size > 0 || orgUptimeMap.size > 0)) {
|
||||||
// Sort org IDs to ensure consistent lock ordering
|
// Sort org IDs to ensure consistent lock ordering
|
||||||
const allOrgIds = [...new Set([...orgUsageMap.keys(), ...orgUptimeMap.keys()])].sort();
|
const allOrgIds = [
|
||||||
|
...new Set([...orgUsageMap.keys(), ...orgUptimeMap.keys()])
|
||||||
|
].sort();
|
||||||
|
|
||||||
for (const orgId of allOrgIds) {
|
for (const orgId of allOrgIds) {
|
||||||
try {
|
try {
|
||||||
@@ -237,10 +247,7 @@ export async function updateSiteBandwidth(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(`Error processing usage for org ${orgId}:`, error);
|
||||||
`Error processing usage for org ${orgId}:`,
|
|
||||||
error
|
|
||||||
);
|
|
||||||
// Continue with other orgs
|
// Continue with other orgs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user