perf(api): tweak cachedEventHandler
parameters
This commit is contained in:
parent
6a35c4affc
commit
eb69412fd1
@ -1,6 +1,14 @@
|
|||||||
import { SidebarItem } from "@models/sidebarEntry";
|
import { SidebarItem } from "@models/sidebarEntry";
|
||||||
|
|
||||||
export default cachedEventHandler(async (ev) => {
|
export default cachedEventHandler(
|
||||||
|
async (ev) => {
|
||||||
const si = await SidebarItem.find({});
|
const si = await SidebarItem.find({});
|
||||||
return si.map((a) => a.toObject());
|
return si.map((a) => a.toObject());
|
||||||
});
|
},
|
||||||
|
{
|
||||||
|
getKey(event) {
|
||||||
|
return "sidebar";
|
||||||
|
},
|
||||||
|
maxAge: 60 * 10,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
import { listQuerier } from "@server/dbHelpers";
|
import { listQuerier } from "@server/dbHelpers";
|
||||||
import { isLoggedIn } from "@server/middlewareButNotReally";
|
import { isLoggedIn } from "@server/middlewareButNotReally";
|
||||||
export default cachedEventHandler(async (ev) => {
|
export default cachedEventHandler(
|
||||||
|
async (ev) => {
|
||||||
isLoggedIn(ev);
|
isLoggedIn(ev);
|
||||||
const id = ev.context.currentUser!._id;
|
const id = ev.context.currentUser!._id;
|
||||||
let s = await listQuerier({ author: id }, ev.context, ev);
|
let s = await listQuerier({ author: { $in: [id] } }, ev.context, ev);
|
||||||
return {
|
return {
|
||||||
stories: s.stories,
|
stories: s?.stories || [],
|
||||||
total: s.stories.length,
|
total: s?.stories.length || 0,
|
||||||
};
|
};
|
||||||
});
|
},
|
||||||
|
{
|
||||||
|
varies: ["Cookie"],
|
||||||
|
getKey(event) {
|
||||||
|
return `${event.context.currentUser?._id || null}/stories`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user