.❀ tablet ❀.
.❀ tablet ❀.
TTCTheo's Typesafe Cult
Created by .❀ tablet ❀. on 11/11/2024 in #questions
[next.js] should i cache this query?
here's the query code, for anyone interested. getCurrentUser grabs the currently logged in user for that request based on cookies.
export default async function (
query: any,
limit: number = 0,
json: boolean = false,
page?: number,
sort?: any,
): Promise<{ stories: IStory[]; total: number }> {

let skipAmt = limit * ((page || 1) - 1);
if (skipAmt < 0) skipAmt = 0;
query["chapters.hidden"] = false;
const currentUser = await getCurrentUser()
const ficmasArray = await getFicmasData();
if (currentUser) {
if (!query.author) query.author = {};
if (!query["chapters.bands"]) query["chapters.bands"] = {};
query["chapters.bands"]["$nin"] = currentUser.hiddenBands;
query["author"]["$nin"] = currentUser.hiddenAuthors;
}
query["ficmas"] = {
$nin: ficmasArray!.map((a) => a._id),
};
let stories = await Story.find(query, null)
.collation({ locale: "en" })
.sort(sort ? sort : { "chapters.posted": -1 })
.populate("ficmas")
.populate("ficmas.wisher", "username _id", "User",)
.populate("coAuthor", "username _id profile")
.populate("chapters.bands")
.populate("challenge")
.populate("author", "username _id profile")
.skip(skipAmt)
.limit(limit || 0)
.exec();
let res = stories.filter((a) => a.author != null);
log.debug(JSON.stringify(query), { label: "list query" });
return {
total: await Story.countDocuments(query).exec(),
stories: res.map(x => (!json ? x.toObject({flattenObjectIds: true}) : x.toJSON({flattenObjectIds: true})) as IStory),
};
}
export default async function (
query: any,
limit: number = 0,
json: boolean = false,
page?: number,
sort?: any,
): Promise<{ stories: IStory[]; total: number }> {

let skipAmt = limit * ((page || 1) - 1);
if (skipAmt < 0) skipAmt = 0;
query["chapters.hidden"] = false;
const currentUser = await getCurrentUser()
const ficmasArray = await getFicmasData();
if (currentUser) {
if (!query.author) query.author = {};
if (!query["chapters.bands"]) query["chapters.bands"] = {};
query["chapters.bands"]["$nin"] = currentUser.hiddenBands;
query["author"]["$nin"] = currentUser.hiddenAuthors;
}
query["ficmas"] = {
$nin: ficmasArray!.map((a) => a._id),
};
let stories = await Story.find(query, null)
.collation({ locale: "en" })
.sort(sort ? sort : { "chapters.posted": -1 })
.populate("ficmas")
.populate("ficmas.wisher", "username _id", "User",)
.populate("coAuthor", "username _id profile")
.populate("chapters.bands")
.populate("challenge")
.populate("author", "username _id profile")
.skip(skipAmt)
.limit(limit || 0)
.exec();
let res = stories.filter((a) => a.author != null);
log.debug(JSON.stringify(query), { label: "list query" });
return {
total: await Story.countDocuments(query).exec(),
stories: res.map(x => (!json ? x.toObject({flattenObjectIds: true}) : x.toJSON({flattenObjectIds: true})) as IStory),
};
}
3 replies
TTCTheo's Typesafe Cult
Created by .❀ tablet ❀. on 7/20/2024 in #questions
is manually setting props of a component returned by a render prop considered bad practice?
now that i think of it, i should use a context instead of "injecting" props posthumously
12 replies
TTCTheo's Typesafe Cult
Created by .❀ tablet ❀. on 7/20/2024 in #questions
is manually setting props of a component returned by a render prop considered bad practice?
two words: bad architecture
12 replies