Skip to content

Commit

Permalink
Fix order of cached DB for get_articles_by_slug
Browse files Browse the repository at this point in the history
  • Loading branch information
leomet07 committed Jan 31, 2024
1 parent 3996c92 commit 62fb81b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ async function applyTextImageCredit(
);

if (!current_extra) {
throw new Error("No current extra found matching index " + img_index + " !");
throw new Error(
"No current extra found matching index " + img_index + " !"
);
}

const current_contributor = current_extra.contributors[0];
Expand Down Expand Up @@ -205,9 +207,9 @@ async function get_articles_by_author(
async function get_articles_by_query(
query: any,
num?: number,
db_param?: Db,
skip_num?: number,
fetch_text?: boolean
fetch_text?: boolean,
db_param?: Db
): Promise<ReceivedArticle[]> {
const db = db_param ?? (await clientPromise).db();
let articles_collection = await db.collection("articles");
Expand Down Expand Up @@ -306,7 +308,9 @@ async function get_media_by_author(author_id: mongoObjectId, num?: number) {
cover_image_contributor: new ObjectId(String(author_id)),
},
num,
db
0,
false,
db // use cached DB
);

let media = articles.map((v) => {
Expand All @@ -318,9 +322,9 @@ async function get_media_by_author(author_id: mongoObjectId, num?: number) {

let extras_collection = await db.collection("article_extras");

type ExtraWithArticle = Omit<ReceivedArticleExtra, 'article'> & {
type ExtraWithArticle = Omit<ReceivedArticleExtra, "article"> & {
article: ReceivedArticle[];
}
};

const article_extras = (
await extras_collection
Expand Down

0 comments on commit 62fb81b

Please sign in to comment.