Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Mongo driver to v6.9.0 #4680

Merged
merged 24 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
57ce741
update mongo driver to v6.9.0
nick-funk Sep 30, 2024
71f6275
WIP: update query types
nick-funk Sep 30, 2024
b526cc6
WIP: more type updates across various server files
nick-funk Oct 1, 2024
a16db72
WIP: more type fixes and updates
nick-funk Oct 1, 2024
a6ebd6b
WIP: even more type fixes
nick-funk Oct 1, 2024
045bd49
replace `remove` with `delete`
nick-funk Oct 6, 2024
267dd6b
resolve types for `signingSecret` logic
nick-funk Oct 6, 2024
cbbb564
update tenant cache types
nick-funk Oct 6, 2024
222e71d
resolve types for metrics
nick-funk Oct 6, 2024
33c914a
fix `seenComments` types
nick-funk Oct 7, 2024
6e635a9
update types for site batch update in migration
nick-funk Oct 7, 2024
a6a8f38
create section and connection filter types for comment actions
nick-funk Oct 7, 2024
169eab4
fix merged moderation queue filter types
nick-funk Oct 7, 2024
de2bf8f
replace collection type on `updateRelatedCommentCounts`
nick-funk Oct 7, 2024
fb56ddf
fix comment count generics updates
nick-funk Oct 7, 2024
e14f392
Merge branch 'develop' into feat/update-mongo
nick-funk Oct 7, 2024
e2d2dfa
make update count type happy for story update
nick-funk Oct 7, 2024
0dd7841
add `SITE_NOT_FOUND` error code to common lib
nick-funk Oct 7, 2024
6010f68
force story types on merge mutator
nick-funk Oct 7, 2024
6c66630
patch text encode/decode global for affected tests
nick-funk Oct 7, 2024
34cbf94
Merge branch 'develop' into feat/update-mongo
nick-funk Oct 7, 2024
370106b
remove todo as it is resolved
nick-funk Oct 8, 2024
4ad39f5
use `countDocuments` over `count` in `countTenantSites`
nick-funk Oct 8, 2024
be604fd
Merge branch 'develop' into feat/update-mongo
nick-funk Oct 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"metascraper-description": "^5.22.5",
"metascraper-image": "^5.22.5",
"metascraper-title": "^5.22.5",
"mongodb": "^3.5.9",
"mongodb": "^6.9.0",
"mongodb-core": "^3.2.7",
"ms": "^2.1.2",
"node-fetch": "^2.6.1",
Expand Down Expand Up @@ -201,7 +201,6 @@
"@types/luxon": "^1.22.0",
"@types/marked": "^0.7.3",
"@types/mini-css-extract-plugin": "^1.4.3",
"@types/mongodb": "3.1.22",
"@types/ms": "^0.7.31",
"@types/node": "^12.12.34",
"@types/node-fetch": "^2.5.5",
Expand Down Expand Up @@ -363,11 +362,6 @@
"Newer versions has problems with using nunjucks.",
"Update when the following issue is resolved:",
"https://github.com/tj/consolidate.js/issues/244"
],
"@types/[email protected]": [
"Newer versions has problems with optional fields when querying with null",
"Update when the following issue is resolved:",
"https://github.com/DefinitelyTyped/DefinitelyTyped/issues/47686"
]
},
"graphql-schema-linter": {
Expand Down
117 changes: 79 additions & 38 deletions server/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions server/src/core/server/app/middleware/csp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AppOptions } from "coral-server/app";
import { getOrigin, prefixSchemeIfRequired } from "coral-server/app/url";
import { Config } from "coral-server/config";
import { MongoContext } from "coral-server/data/context";
import { SiteNotFoundError } from "coral-server/errors";
import {
retrieveSite,
retrieveSiteByOrigin,
Expand Down Expand Up @@ -50,6 +51,10 @@ async function retrieveSiteFromQuery(
return null;
}

if (!story.siteID) {
throw new SiteNotFoundError(null, storyID);
}

// If the site can't be found based on it's allowed origins and the story
// URL (which is a allowed list), then we know it isn't allowed.
return retrieveSite(mongo, tenant.id, story.siteID);
Expand Down
6 changes: 5 additions & 1 deletion server/src/core/server/app/middleware/tenant.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { v1 as uuid } from "uuid";

import { MongoContext } from "coral-server/data/context";
import { TenantNotFoundError } from "coral-server/errors";
import { SiteNotFoundError, TenantNotFoundError } from "coral-server/errors";
import logger from "coral-server/logger";
import {
retrieveSite,
Expand Down Expand Up @@ -110,6 +110,10 @@ async function retrieveSiteFromQuery(
return null;
}

if (!story.siteID) {
throw new SiteNotFoundError(null, storyID);
}

// If the site can't be found based on it's allowed origins and the story
// URL (which is a allowed list), then we know it isn't allowed.
return retrieveSite(mongo, tenant.id, story.siteID);
Expand Down
4 changes: 2 additions & 2 deletions server/src/core/server/data/cache/commentCache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const createRedis = (): AugmentedRedis => {

const createMongo = async (): Promise<MongoContext> => {
const uri = "mongodb://127.0.0.1:27017/coral";
const live = await createMongoDB(uri);
const archive = await createMongoDB(uri);
const live = (await createMongoDB(uri)).db;
const archive = (await createMongoDB(uri)).db;

const context = new MongoContextImpl(live, archive);

Expand Down
12 changes: 8 additions & 4 deletions server/src/core/server/data/cache/commentCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ export class CommentCache implements IDataCache {
: this.mongo.comments();

const comments = await collection
.find({ tenantID, storyID, status: { $in: ["APPROVED", "NONE"] } })
.find({
tenantID,
storyID,
status: { $in: [GQLCOMMENT_STATUS.APPROVED, GQLCOMMENT_STATUS.NONE] },
})
.toArray();
if (!comments || comments.length === 0) {
return [];
Expand Down Expand Up @@ -350,20 +354,20 @@ export class CommentCache implements IDataCache {
tenantID: string,
storyID: string,
parentID?: string | null,
isArchived?: boolean
isArchived?: boolean | null
): Promise<Array<Readonly<Comment>>> {
const filter = parentID
? {
tenantID,
storyID,
parentID,
status: { $in: ["APPROVED", "NONE"] },
status: { $in: [GQLCOMMENT_STATUS.APPROVED, GQLCOMMENT_STATUS.NONE] },
}
: {
tenantID,
storyID,
parentID: null,
status: { $in: ["APPROVED", "NONE"] },
status: { $in: [GQLCOMMENT_STATUS.APPROVED, GQLCOMMENT_STATUS.NONE] },
};

const collection = isArchived
Expand Down
4 changes: 2 additions & 2 deletions server/src/core/server/data/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export async function createMongoContext(
): Promise<MongoContext> {
// Setup MongoDB.
const liveURI = config.get("mongodb");
const live = await createMongoDB(liveURI);
const live = (await createMongoDB(liveURI)).db;

// If we have an archive URI, use it, otherwise, default
// to using the live database
Expand All @@ -154,7 +154,7 @@ export async function createMongoContext(
) {
archive = live;
} else {
archive = await createMongoDB(archiveURI);
archive = (await createMongoDB(archiveURI)).db;
}

return new MongoContextImpl(live, archive);
Expand Down
12 changes: 10 additions & 2 deletions server/src/core/server/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,15 @@ export class StoryNotFoundError extends CoralError {
}
}

export class SiteNotFoundError extends CoralError {
constructor(siteID?: string | null, storyID?: string | null) {
super({
code: ERROR_CODES.SITE_NOT_FOUND,
context: { pub: { siteID, storyID } },
});
}
}

export class CommentNotFoundError extends CoralError {
constructor(commentID: string) {
super({
Expand Down Expand Up @@ -1037,9 +1046,8 @@ export class UsernameAlreadyExists extends CoralError {
}

export class UnableToUpdateStoryURL extends CoralError {
constructor(cause: MongoError, id: string, oldUrl: string, url: string) {
constructor(id: string, oldUrl: string, url: string) {
super({
cause,
reportable: true,
code: ERROR_CODES.UNABLE_TO_UPDATE_STORY_URL,
context: { pvt: { id, oldUrl, url } },
Expand Down
Loading
Loading