mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-02 16:19:08 +00:00
Fixing various bugs
This commit is contained in:
@@ -1086,10 +1086,8 @@ async function getDomainId(
|
||||
|
||||
// remove the base domain of the domain
|
||||
let subdomain = null;
|
||||
if (domainSelection.type == "ns" || domainSelection.type == "wildcard") {
|
||||
if (fullDomain != baseDomain) {
|
||||
subdomain = fullDomain.replace(`.${baseDomain}`, "");
|
||||
}
|
||||
if (fullDomain != baseDomain) {
|
||||
subdomain = fullDomain.replace(`.${baseDomain}`, "");
|
||||
}
|
||||
|
||||
// Return the first valid domain
|
||||
|
||||
@@ -247,7 +247,7 @@ export async function getNextAvailableClientSubnet(
|
||||
orgId: string,
|
||||
transaction: Transaction | typeof db = db
|
||||
): 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) {
|
||||
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`);
|
||||
}
|
||||
|
||||
const existingAddressesSites = await db
|
||||
const existingAddressesSites = await transaction
|
||||
.select({
|
||||
address: sites.address
|
||||
})
|
||||
.from(sites)
|
||||
.where(and(isNotNull(sites.address), eq(sites.orgId, orgId)));
|
||||
|
||||
const existingAddressesClients = await db
|
||||
const existingAddressesClients = await transaction
|
||||
.select({
|
||||
address: clients.subnet
|
||||
})
|
||||
|
||||
@@ -160,12 +160,20 @@ export async function updateSiteBandwidth(
|
||||
|
||||
// Aggregate bandwidth usage for the org
|
||||
const totalBandwidth = peer.bytesIn + peer.bytesOut;
|
||||
const currentOrgUsage = orgUsageMap.get(updatedSite.orgId) || 0;
|
||||
orgUsageMap.set(updatedSite.orgId, currentOrgUsage + totalBandwidth);
|
||||
const currentOrgUsage =
|
||||
orgUsageMap.get(updatedSite.orgId) || 0;
|
||||
orgUsageMap.set(
|
||||
updatedSite.orgId,
|
||||
currentOrgUsage + totalBandwidth
|
||||
);
|
||||
|
||||
// Add 10 seconds of uptime for each active site
|
||||
const currentOrgUptime = orgUptimeMap.get(updatedSite.orgId) || 0;
|
||||
orgUptimeMap.set(updatedSite.orgId, currentOrgUptime + 10 / 60);
|
||||
const currentOrgUptime =
|
||||
orgUptimeMap.get(updatedSite.orgId) || 0;
|
||||
orgUptimeMap.set(
|
||||
updatedSite.orgId,
|
||||
currentOrgUptime + 10 / 60
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
@@ -181,7 +189,9 @@ export async function updateSiteBandwidth(
|
||||
// This separates the concerns and reduces lock contention
|
||||
if (calcUsageAndLimits && (orgUsageMap.size > 0 || orgUptimeMap.size > 0)) {
|
||||
// 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) {
|
||||
try {
|
||||
@@ -237,10 +247,7 @@ export async function updateSiteBandwidth(
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Error processing usage for org ${orgId}:`,
|
||||
error
|
||||
);
|
||||
logger.error(`Error processing usage for org ${orgId}:`, error);
|
||||
// Continue with other orgs
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user