Skip to content

Commit ba9cdde

Browse files
committed
fix: internalize download counter mutations
1 parent 8d5a64b commit ba9cdde

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

convex/downloads.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { v } from 'convex/values'
22
import { api, internal } from './_generated/api'
3-
import { httpAction, internalMutation, mutation } from './functions'
3+
import { httpAction, internalMutation } from './functions'
44
import { getOptionalApiTokenUserId } from './lib/apiTokenAuth'
55
import { applyRateLimit, getClientIp } from './lib/httpRateLimit'
66
import { corsHeaders, mergeHeaders } from './lib/httpHeaders'
@@ -145,19 +145,6 @@ export const downloadZip = httpAction(async (ctx, request) => {
145145
})
146146
})
147147

148-
export const increment = mutation({
149-
args: { skillId: v.id('skills') },
150-
handler: async (ctx, args) => {
151-
// Skip db.get to avoid adding the skill doc to the read set.
152-
// The calling HTTP action already validated the skill exists,
153-
// and the stat processor handles deleted skills gracefully.
154-
await insertStatEvent(ctx, {
155-
skillId: args.skillId,
156-
kind: 'download',
157-
})
158-
},
159-
})
160-
161148
export const recordDownloadInternal = internalMutation({
162149
args: {
163150
skillId: v.id('skills'),

convex/httpApiV1.handlers.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @vitest-environment node */
22
import { beforeEach, describe, expect, it, vi } from 'vitest'
3+
import { internal } from './_generated/api'
34

45
vi.mock('./lib/apiTokenAuth', () => ({
56
requireApiTokenUser: vi.fn(),
@@ -634,6 +635,9 @@ describe('httpApiV1 handlers', () => {
634635
expect(response.status).toBe(200)
635636
expect(await response.text()).toBe('hello')
636637
expect(storageGet).toHaveBeenCalledWith('_storage:1')
638+
expect(runMutation).toHaveBeenCalledWith(internal.soulDownloads.incrementInternal, {
639+
soulId: 'souls:1',
640+
})
637641
})
638642

639643
it('lists skills supports sort aliases', async () => {

convex/httpApiV1/soulsV1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export async function soulsGetRouterV1Handler(ctx: ActionCtx, request: Request)
265265
if (!blob) return text('File missing in storage', 410, rate.headers)
266266
const textContent = await blob.text()
267267

268-
void ctx.runMutation(api.soulDownloads.increment, { soulId: soul._id })
268+
void ctx.runMutation(internal.soulDownloads.incrementInternal, { soulId: soul._id })
269269
return safeTextFileResponse({
270270
textContent,
271271
path: file.path,

convex/soulDownloads.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { v } from 'convex/values'
2-
import { mutation } from './functions'
2+
import { internalMutation } from './functions'
33

4-
export const increment = mutation({
4+
export const incrementInternal = internalMutation({
55
args: { soulId: v.id('souls') },
66
handler: async (ctx, args) => {
77
const soul = await ctx.db.get(args.soulId)

0 commit comments

Comments
 (0)