From 8606b5e5ded9715a278146534ca06d6c9a37280c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 25 Jun 2025 11:39:05 +0800 Subject: [PATCH 1/5] donwgrade mongo functoins --- server/db/mongo/modules/checkModule.js | 4 ++-- server/db/mongo/modules/diagnosticModule.js | 2 +- server/db/mongo/modules/monitorModule.js | 8 +++---- .../db/mongo/modules/monitorModuleQueries.js | 21 ++++++++++++------- server/db/mongo/modules/statusPageModule.js | 18 ++++------------ 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/server/db/mongo/modules/checkModule.js b/server/db/mongo/modules/checkModule.js index f409fd3d2..a53384d1a 100755 --- a/server/db/mongo/modules/checkModule.js +++ b/server/db/mongo/modules/checkModule.js @@ -73,7 +73,7 @@ const getChecksByMonitor = async ({ rowsPerPage = parseInt(rowsPerPage); // Match const matchStage = { - monitorId: ObjectId.createFromHexString(monitorId), + monitorId: new ObjectId(monitorId), ...(typeof status !== "undefined" && { status }), ...(dateRangeLookup[dateRange] && { createdAt: { @@ -161,7 +161,7 @@ const getChecksByTeam = async ({ page = parseInt(page); rowsPerPage = parseInt(rowsPerPage); const matchStage = { - teamId: ObjectId.createFromHexString(teamId), + teamId: new ObjectId(teamId), status: false, ...(dateRangeLookup[dateRange] && { createdAt: { diff --git a/server/db/mongo/modules/diagnosticModule.js b/server/db/mongo/modules/diagnosticModule.js index 7a51ad193..e59830518 100755 --- a/server/db/mongo/modules/diagnosticModule.js +++ b/server/db/mongo/modules/diagnosticModule.js @@ -19,7 +19,7 @@ const getMonitorsByTeamIdExecutionStats = async (req) => { order = "asc"; } // Build match stage - const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) }; + const matchStage = { teamId: new ObjectId(req.params.teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } diff --git a/server/db/mongo/modules/monitorModule.js b/server/db/mongo/modules/monitorModule.js index 32ed8b146..bc31915c2 100755 --- a/server/db/mongo/modules/monitorModule.js +++ b/server/db/mongo/modules/monitorModule.js @@ -523,7 +523,7 @@ const getMonitorsByTeamId = async ({ order = "asc"; } // Build match stage - const matchStage = { teamId: ObjectId.createFromHexString(teamId) }; + const matchStage = { teamId: new ObjectId(teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } @@ -563,8 +563,7 @@ const getMonitorsByTeamId = async ({ const getMonitorsAndSummaryByTeamId = async ({ type, explain, teamId }) => { try { - const parsedTeamId = ObjectId.createFromHexString(teamId); - const matchStage = { teamId: parsedTeamId }; + const matchStage = { teamId: new ObjectId(teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } @@ -606,9 +605,8 @@ const getMonitorsWithChecksByTeamId = async ({ field = "name"; order = "asc"; } - const parsedTeamId = ObjectId.createFromHexString(teamId); // Build match stage - const matchStage = { teamId: parsedTeamId }; + const matchStage = { teamId: new ObjectId(teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } diff --git a/server/db/mongo/modules/monitorModuleQueries.js b/server/db/mongo/modules/monitorModuleQueries.js index 35ddb8478..ab45eebb6 100755 --- a/server/db/mongo/modules/monitorModuleQueries.js +++ b/server/db/mongo/modules/monitorModuleQueries.js @@ -4,7 +4,7 @@ const buildUptimeDetailsPipeline = (monitorId, dates, dateString) => { return [ { $match: { - monitorId: ObjectId.createFromHexString(monitorId), + monitorId: new ObjectId(monitorId), createdAt: { $gte: dates.start, $lte: dates.end }, }, }, @@ -407,6 +407,16 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => { ], }, }, + { $unwind: "$checks" }, + { $sort: { "checks._id": 1 } }, + { + $group: { + _id: "$_id", + checks: { $push: "$checks" }, + aggregateData: { $first: "$aggregateData" }, + upChecks: { $first: "$upChecks" }, + }, + }, { $project: { aggregateData: { @@ -415,12 +425,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => { upChecks: { $arrayElemAt: ["$upChecks", 0], }, - checks: { - $sortArray: { - input: "$checks", - sortBy: { _id: 1 }, - }, - }, + checks: 1, }, }, ]; @@ -734,7 +739,7 @@ const buildGetMonitorsByTeamIdPipeline = (req) => { order = "asc"; } // Build the match stage - const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) }; + const matchStage = { teamId: new ObjectId(req.params.teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } diff --git a/server/db/mongo/modules/statusPageModule.js b/server/db/mongo/modules/statusPageModule.js index e94ffbd55..f0f2fa762 100755 --- a/server/db/mongo/modules/statusPageModule.js +++ b/server/db/mongo/modules/statusPageModule.js @@ -134,6 +134,9 @@ const getStatusPage = async (url) => { }, }, }, + { $match: { "monitors.orderIndex": { $ne: -1 } } }, + { $sort: { "monitors.orderIndex": 1 } }, + { $group: { _id: "$_id", @@ -156,20 +159,7 @@ const getStatusPage = async (url) => { showAdminLoginLink: 1, url: 1, }, - monitors: { - $filter: { - input: { - $sortArray: { - input: "$monitors", - sortBy: { orderIndex: 1 }, - }, - }, - as: "monitor", - cond: { - $ne: ["$$monitor.orderIndex", -1], - }, - }, - }, + monitors: 1, }, }, ]); From b03f9513526b10aba3f0ef15e10231860c512e2f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 25 Jun 2025 11:56:04 +0800 Subject: [PATCH 2/5] version fix --- .github/workflows/deploy-images.yml | 10 ++++++++++ .github/workflows/production-deploy.yml | 4 ++++ .github/workflows/staging-deploy.yml | 4 ++++ client/vite.config.js | 15 ++++++++------- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy-images.yml b/.github/workflows/deploy-images.yml index d3d70b90b..ccc2104bc 100644 --- a/.github/workflows/deploy-images.yml +++ b/.github/workflows/deploy-images.yml @@ -18,12 +18,16 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get version + id: vars + run: echo "VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV - name: Build Client Docker image run: | docker build \ -t ghcr.io/bluewave-labs/checkmate-client:latest \ -f ./docker/dist/client.Dockerfile \ --label org.opencontainers.image.source=https://github.com/bluewave-labs/checkmate \ + --build-arg VITE_APP_VERSION=${{ env.VERSION }} \ . - name: Push Client Docker image @@ -96,6 +100,10 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get version + id: vars + run: echo "VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV + - name: Build and push multi-arch Docker image uses: docker/build-push-action@v5 with: @@ -107,6 +115,8 @@ jobs: platforms: linux/amd64,linux/arm64 labels: | org.opencontainers.image.source=https://github.com/bluewave-labs/checkmate + build-args: | + VITE_APP_VERSION=${{ env.VERSION }} docker-build-and-push-server-mono: runs-on: ubuntu-latest diff --git a/.github/workflows/production-deploy.yml b/.github/workflows/production-deploy.yml index 6956f5caa..4275b4a00 100644 --- a/.github/workflows/production-deploy.yml +++ b/.github/workflows/production-deploy.yml @@ -18,12 +18,16 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get version + id: vars + run: echo "VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV - name: Build Client Docker image run: | docker build \ -t ghcr.io/bluewave-labs/checkmate:frontend-demo \ -f ./docker/prod/client.Dockerfile \ --label org.opencontainers.image.source=https://github.com/bluewave-labs/checkmate \ + --build-arg VITE_APP_VERSION=${{ env.VERSION }} \ . - name: Push Client Docker image diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index 34fa243c6..de0dbfed4 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -18,12 +18,16 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get version + id: vars + run: echo "VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV - name: Build Client Docker image run: | docker build \ -t ghcr.io/bluewave-labs/checkmate:frontend-staging \ -f ./docker/staging/client.Dockerfile \ --label org.opencontainers.image.source=https://github.com/bluewave-labs/checkmate \ + --build-arg VITE_APP_VERSION=${{ env.VERSION }} \ . - name: Push Client Docker image diff --git a/client/vite.config.js b/client/vite.config.js index 96151c0b3..e930a20e9 100644 --- a/client/vite.config.js +++ b/client/vite.config.js @@ -5,13 +5,14 @@ import { execSync } from "child_process"; export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), ""); - let version; - try { - version = - env.VITE_APP_VERSION || - execSync("git describe --tags --abbrev=0").toString().trim(); - } catch (error) { - version = "unknown"; + let version = env.VITE_APP_VERSION; + + if (!version) { + try { + version = execSync("git describe --tags --abbrev=0").toString().trim(); + } catch { + version = "unknown"; + } } return { From 4fa0e085748b60c389edaaebc37693247c937e1c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 25 Jun 2025 12:07:12 +0800 Subject: [PATCH 3/5] update workflows --- .github/workflows/deploy-images-on-release.yml | 10 ++++++++++ .github/workflows/deploy-images.yml | 11 +++++++++++ .github/workflows/production-deploy.yml | 2 ++ 3 files changed, 23 insertions(+) diff --git a/.github/workflows/deploy-images-on-release.yml b/.github/workflows/deploy-images-on-release.yml index f1d0dd7ce..cf06f7840 100644 --- a/.github/workflows/deploy-images-on-release.yml +++ b/.github/workflows/deploy-images-on-release.yml @@ -11,6 +11,9 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Extract version from tag id: extract_tag run: echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" @@ -93,6 +96,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -119,12 +124,16 @@ jobs: platforms: linux/amd64,linux/arm64 labels: | org.opencontainers.image.source=https://github.com/bluewave-labs/checkmate + build-args: | + VITE_APP_VERSION=${{ steps.extract_tag.outputs.version }} docker-build-and-push-server-mono: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Extract version id: extract_tag @@ -143,6 +152,7 @@ jobs: -t ghcr.io/bluewave-labs/checkmate-backend-mono:${{ steps.extract_tag.outputs.version }} \ -f ./docker/dist-mono/server.Dockerfile \ --label org.opencontainers.image.source=https://github.com/bluewave-labs/checkmate \ + --build-arg VITE_APP_VERSION=${{ steps.extract_tag.outputs.version }} \ . - name: Push Server Docker image diff --git a/.github/workflows/deploy-images.yml b/.github/workflows/deploy-images.yml index ccc2104bc..fa39fed85 100644 --- a/.github/workflows/deploy-images.yml +++ b/.github/workflows/deploy-images.yml @@ -10,6 +10,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Log in to GitHub Container Registry uses: docker/login-action@v3 @@ -89,6 +91,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -123,6 +127,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Log in to GitHub Container Registry uses: docker/login-action@v3 @@ -131,12 +137,17 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get version + id: vars + run: echo "VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV + - name: Build Server Docker image run: | docker build \ -t ghcr.io/bluewave-labs/checkmate-backend-mono:latest \ -f ./docker/dist-mono/server.Dockerfile \ --label org.opencontainers.image.source=https://github.com/bluewave-labs/checkmate \ + --build-arg VITE_APP_VERSION=${{ env.VERSION }} \ . - name: Push Server Docker image diff --git a/.github/workflows/production-deploy.yml b/.github/workflows/production-deploy.yml index 4275b4a00..7764c488b 100644 --- a/.github/workflows/production-deploy.yml +++ b/.github/workflows/production-deploy.yml @@ -10,6 +10,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Log in to GitHub Container Registry uses: docker/login-action@v3 From b718c02787a48d6bbc6db7e4f2d4382ce4876198 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 25 Jun 2025 12:07:31 +0800 Subject: [PATCH 4/5] update workflows --- .github/workflows/staging-deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index de0dbfed4..ea5477815 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -10,6 +10,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Log in to GitHub Container Registry uses: docker/login-action@v3 From ba8011a22ec60fafe91e67fb252f34c7e0c9f45f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 25 Jun 2025 12:17:16 +0800 Subject: [PATCH 5/5] use process.env --- client/vite.config.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/vite.config.js b/client/vite.config.js index e930a20e9..20943eeb4 100644 --- a/client/vite.config.js +++ b/client/vite.config.js @@ -4,10 +4,8 @@ import svgr from "vite-plugin-svgr"; import { execSync } from "child_process"; export default defineConfig(({ mode }) => { - const env = loadEnv(mode, process.cwd(), ""); - let version = env.VITE_APP_VERSION; - - if (!version) { + let version = process.env.VITE_APP_VERSION; + if (!version || version === "unknown") { try { version = execSync("git describe --tags --abbrev=0").toString().trim(); } catch {