Skip to content

Commit

Permalink
Eliminate unnecessary queries (#2160)
Browse files Browse the repository at this point in the history
Removes some unnecessary queries from the hot path for feed serving.
  • Loading branch information
robknight authored Nov 12, 2024
1 parent 18c53b0 commit 82b9f6f
Show file tree
Hide file tree
Showing 7 changed files with 987 additions and 1,005 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,30 +196,30 @@ export class CSVPipeline implements BasePipeline {
requesterSemaphoreV4Id = semaphoreV4Id;
// Consumer is validated, so save them in the consumer list

let didUpdate = false;

await sqlTransaction(this.context.dbPool, async (client) => {
for (const email of emails) {
didUpdate =
didUpdate ||
(await this.consumerDB.save(
client,
this.id,
email.email,
semaphoreId,
new Date()
));
}

if (this.definition.options.semaphoreGroupName) {
// If the user's Semaphore commitment has changed, `didUpdate` will be
// true, and we need to update the Semaphore groups
if (didUpdate) {
span?.setAttribute("semaphore_groups_updated", true);
await this.triggerSemaphoreGroupUpdate(client);
}
}
});
// let didUpdate = false;

// await sqlTransaction(this.context.dbPool, async (client) => {
// for (const email of emails) {
// didUpdate =
// didUpdate ||
// (await this.consumerDB.save(
// client,
// this.id,
// email.email,
// semaphoreId,
// new Date()
// ));
// }

// if (this.definition.options.semaphoreGroupName) {
// // If the user's Semaphore commitment has changed, `didUpdate` will be
// // true, and we need to update the Semaphore groups
// if (didUpdate) {
// span?.setAttribute("semaphore_groups_updated", true);
// await this.triggerSemaphoreGroupUpdate(client);
// }
// }
// });
} catch (e) {
logger(LOG_TAG, "credential PCD not verified for req", req);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,29 +216,29 @@ export class CSVTicketPipeline implements BasePipeline {
requesterSemaphoreId = semaphoreId;
requesterSemaphoreV4Id = semaphoreV4Id;
// Consumer is validated, so save them in the consumer list
let didUpdate = false;
await sqlTransaction(this.context.dbPool, async (client) => {
for (const email of emails) {
didUpdate =
didUpdate ||
(await this.consumerDB.save(
client,
this.id,
email.email,
semaphoreId,
new Date()
));
}

if (this.definition.options.semaphoreGroupName) {
// If the user's Semaphore commitment has changed, `didUpdate` will be
// true, and we need to update the Semaphore groups
if (didUpdate) {
span?.setAttribute("semaphore_groups_updated", true);
await this.triggerSemaphoreGroupUpdate(client);
}
}
});
// let didUpdate = false;
// await sqlTransaction(this.context.dbPool, async (client) => {
// for (const email of emails) {
// didUpdate =
// didUpdate ||
// (await this.consumerDB.save(
// client,
// this.id,
// email.email,
// semaphoreId,
// new Date()
// ));
// }

// if (this.definition.options.semaphoreGroupName) {
// // If the user's Semaphore commitment has changed, `didUpdate` will be
// // true, and we need to update the Semaphore groups
// if (didUpdate) {
// span?.setAttribute("semaphore_groups_updated", true);
// await this.triggerSemaphoreGroupUpdate(client);
// }
// }
// });
} catch (e) {
logger(LOG_TAG, "credential PCD not verified for req", req);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,28 +858,28 @@ export class LemonadePipeline implements BasePipeline {
span?.setAttribute("emails", emails.map((e) => e.email).join(","));
span?.setAttribute("semaphore_id", semaphoreId);

let didUpdate = false;
for (const email of emails) {
// Consumer is validated, so save them in the consumer list
didUpdate =
didUpdate ||
(await this.consumerDB.save(
client,
this.id,
email.email,
semaphoreId,
new Date()
));
}

if ((this.definition.options.semaphoreGroups ?? []).length > 0) {
// If the user's Semaphore commitment has changed, `didUpdate` will be
// true, and we need to update the Semaphore groups
if (didUpdate) {
span?.setAttribute("semaphore_groups_updated", true);
await this.triggerSemaphoreGroupUpdate(client);
}
}
// let didUpdate = false;
// for (const email of emails) {
// // Consumer is validated, so save them in the consumer list
// didUpdate =
// didUpdate ||
// (await this.consumerDB.save(
// client,
// this.id,
// email.email,
// semaphoreId,
// new Date()
// ));
// }

// if ((this.definition.options.semaphoreGroups ?? []).length > 0) {
// // If the user's Semaphore commitment has changed, `didUpdate` will be
// // true, and we need to update the Semaphore groups
// if (didUpdate) {
// span?.setAttribute("semaphore_groups_updated", true);
// await this.triggerSemaphoreGroupUpdate(client);
// }
// }

const tickets = (
await Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1187,50 +1187,50 @@ export class PretixPipeline implements BasePipeline {
span?.setAttribute("email", emails.map((e) => e.email).join(","));
span?.setAttribute("semaphore_id", semaphoreId);

let didUpdate = false;
//let didUpdate = false;

return namedSqlTransaction(this.context.dbPool, "", async (client) => {
for (const e of emails) {
didUpdate =
didUpdate ||
(await this.consumerDB.save(
client,
this.id,
e.email,
semaphoreId,
new Date()
));
}

const provider = this.autoIssuanceProvider;
if (provider) {
const newManualTickets = (
await Promise.all(
emails.map(async (e) =>
provider.maybeIssueForUser(
e.email,
await this.getAllManualTickets(client),
await this.db.loadByEmail(this.id, e.email)
)
)
)
).flat();

await Promise.allSettled(
newManualTickets.map((t) =>
this.manualTicketDB.save(client, this.id, t)
)
);
}
// for (const e of emails) {
// didUpdate =
// didUpdate ||
// (await this.consumerDB.save(
// client,
// this.id,
// e.email,
// semaphoreId,
// new Date()
// ));
// }

// const provider = this.autoIssuanceProvider;
// if (provider) {
// const newManualTickets = (
// await Promise.all(
// emails.map(async (e) =>
// provider.maybeIssueForUser(
// e.email,
// await this.getAllManualTickets(client),
// await this.db.loadByEmail(this.id, e.email)
// )
// )
// )
// ).flat();

// await Promise.allSettled(
// newManualTickets.map((t) =>
// this.manualTicketDB.save(client, this.id, t)
// )
// );
// }

// If the user's Semaphore commitment has changed, `didUpdate` will be
// true, and we need to update the Semaphore groups
if ((this.definition.options.semaphoreGroups ?? []).length > 0) {
if (didUpdate) {
span?.setAttribute("semaphore_groups_updated", true);
await this.triggerSemaphoreGroupUpdate(client);
}
}
// if ((this.definition.options.semaphoreGroups ?? []).length > 0) {
// if (didUpdate) {
// span?.setAttribute("semaphore_groups_updated", true);
// await this.triggerSemaphoreGroupUpdate(client);
// }
// }

const tickets = (
await Promise.all(
Expand Down
Loading

0 comments on commit 82b9f6f

Please sign in to comment.