用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/KunanonJ/ai-skills-hub --skill cursor-plugin-convex-rule-no-date-now-in-queries命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | cursor-plugin-convex-rule-no-date-now-in-queries |
| description | Never use Date.now() in queries as it breaks caching and reactivity |
| metadata | {"version":"0.1.0"} |
Never use Date.now() or new Date() inside query functions. It prevents proper caching and breaks reactive subscriptions.
Queries should be deterministic. Using Date.now() means the query returns different results every millisecond, defeating Convex's reactivity system.
export const getActiveTasks = query({
handler: async (ctx) => {
const now = Date.now(); // ❌ Don't do this
return await ctx.db
.query("tasks")
.filter(q => q.lt(q.field("dueDate"), now))
.collect();
},
});
export const getActiveTasks = query({
args: { now: v.number() },
handler: async (ctx, args) => {
return await ctx.db
.query("tasks")
.filter(q => q.lt(q.field("dueDate"), args.now))
.collect();
},
});
// Client passes current time
const tasks = useQuery(api.tasks.getActiveTasks, { now: Date.now() });
// Update status periodically with a cron job
export const updateTaskStatuses = internalMutation({
handler: async (ctx) => {
const now = Date.now();
const expiredTasks = await ctx.db
.query("tasks")
.withIndex("by_status", q => q.eq("status", "active"))
.filter(q => q.lt(q.field("dueDate"), now))
.collect();
for (const task of expiredTasks) {
await ctx.db.patch(task._id, { status: "expired" });
}
},
});
// Query is simple and efficient
export const getActiveTasks = query({
handler: async (ctx) => {
return await ctx.db
.query("tasks")
.withIndex("by_status", => q.(, ))
.();
},
});
If you need day-level filtering:
export const getToday = query({
args: { today: v.string() }, // "2024-01-15"
handler: async (ctx, args) => {
return await ctx.db
.query("events")
.withIndex("by_date", q => q.eq("date", args.today))
.collect();
},
});