mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-11-18 01:54:23 +01:00
perf: index repository lookups and billing maintenance
This commit is contained in:
1 parent
6a230f73b9
commit
3999a71583
14 files changed
+258
-11
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { REPOSITORY_ID_COLLATION } from "../../core/repository-id";
|
||||
import { notificationEmail, normalizeEmail, resetOwnerAccessAlerts } from "../../core/owner-notifications";
|
||||
import { saveRegistrationEmail } from "../../core/registration-email";
|
||||
import * as express from "express";
|
||||
@@ -230,7 +231,7 @@ router.post("/connections/migrate", async (req, res) => {
|
||||
if (typeof id !== "string" || !["repository", "pull-request"].includes(type) || !["oauth", "github-app"].includes(connection)) throw appError("invalid_connection", 400);
|
||||
if (connection === "github-app" && (!config.GITHUB_APP_ENABLED || !config.GITHUB_APP_NEW_CONNECTIONS)) throw appError("github_app_disabled", 503);
|
||||
const isRepo = type === "repository";
|
||||
const model = isRepo ? await RepositoryModel.findOne({ repoId: id, owner: user.id }) : await PullRequestModel.findOne({ pullRequestId: id, owner: user.id });
|
||||
const model = isRepo ? await RepositoryModel.findOne({ repoId: id, owner: user.id }, null, { collation: REPOSITORY_ID_COLLATION }) : await PullRequestModel.findOne({ pullRequestId: id, owner: user.id });
|
||||
if (!model || ["removed", "archived"].includes(model.status || "")) throw appError("repo_not_found", 404);
|
||||
const stalePullRequest = !isRepo && model.status === "download" &&
|
||||
(!model.statusDate || model.statusDate.getTime() <= Date.now() - 5 * 60 * 1000);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { REPOSITORY_ID_COLLATION } from "../core/repository-id";
|
||||
import { reconcileNeverExpiration } from "../core/billing/expiration";
|
||||
import { Model, Document } from "mongoose";
|
||||
import * as schedule from "node-schedule";
|
||||
@@ -185,7 +186,7 @@ export async function runRepositoryStatusCheck(now = new Date()) {
|
||||
for await (const file of pendingCursor) {
|
||||
batch.push((async () => {
|
||||
try {
|
||||
const data = await AnonymizedRepositoryModel.findOne({ repoId: file.repoId }).exec();
|
||||
const data = await AnonymizedRepositoryModel.findOne({ repoId: file.repoId }, null, { collation: REPOSITORY_ID_COLLATION }).exec();
|
||||
if (!data || data.treeGeneration !== file.treeGeneration ||
|
||||
(data.status && [RepositoryStatus.EXPIRING, RepositoryStatus.EXPIRED, RepositoryStatus.REMOVING, RepositoryStatus.REMOVED].includes(data.status))) {
|
||||
await FileModel.deleteOne({ _id: file._id, metadataPending: true }).exec();
|
||||
|
||||
Reference in new issue
Block a user