Open source personal finance application
refactor: remove dead code — deleteTrnsByIds and removeBatch mutation
Ilya Komichevd39bf0f068c2
diff --git a/app/components/categories/useCategoriesStore.test.ts b/app/components/categories/useCategoriesStore.test.tsindex 6aadb300..d3df6765 100644--- a/app/components/categories/useCategoriesStore.test.ts+++ b/app/components/categories/useCategoriesStore.test.ts@@ -31,10 +31,8 @@ vi.stubGlobal('useConvexClientWithApi', () => ({}))const removeTrnsFromStoreMock = vi.fn()-const deleteTrnsByIdsMock = vi.fn()vi.mock('~/components/trns/useTrnsStore', () => ({useTrnsStore: () => ({- deleteTrnsByIds: deleteTrnsByIdsMock,hasItems: false,items: {},removeTrnsFromStore: removeTrnsFromStoreMock,diff --git a/app/components/trns/useTrnsStore.test.ts b/app/components/trns/useTrnsStore.test.tsindex 581022e0..75d6acaf 100644--- a/app/components/trns/useTrnsStore.test.ts+++ b/app/components/trns/useTrnsStore.test.ts@@ -256,24 +256,6 @@ describe('useTrnsStore', () => {})})- describe('deleteTrnsByIds', () => {- it('batch deletes all trns in single mutation', () => {- const store = useTrnsStore()- store.items = {- trn1: makeTrn(),- trn2: makeTrn(),- trn3: makeTrn(),- }-- store.deleteTrnsByIds(['trn1', 'trn3'])-- expect(store.items).not.toHaveProperty('trn1')- expect(store.items).toHaveProperty('trn2')- expect(store.items).not.toHaveProperty('trn3')- expect(mutationMock).toHaveBeenCalledTimes(1)- })- })-describe('removeTrnsFromStore', () => {it('removes trns from store without mutations or queue', () => {const store = useTrnsStore()diff --git a/app/components/trns/useTrnsStore.ts b/app/components/trns/useTrnsStore.tsindex 4795101f..3b0d8dc0 100644--- a/app/components/trns/useTrnsStore.ts+++ b/app/components/trns/useTrnsStore.ts@@ -11,7 +11,7 @@ import type { TrnId, TrnItem, TrnItemFull, Trns, TrnsGetterProps } from '~/compoimport { useCategoriesStore } from '~/components/categories/useCategoriesStore'import { getEndOf, getStartOf } from '~/components/date/utils'import { useDemo } from '~/components/demo/useDemo'-import { pushOfflineOp, removeOfflineOps } from '~/components/offline/helpers'+import { pushOfflineOp } from '~/components/offline/helpers'import { isReplaying } from '~/components/offline/replay'import { STORAGE_KEYS } from '~/components/offline/storageKeys'import { getTrnsIds } from '~/components/trns/getTrns'@@ -299,44 +299,6 @@ export const useTrnsStore = defineStore('trns', () => {})}- function deleteTrnsByIds(trnsIds: TrnId[]) {- if (trnsIds.length === 0)- return-- // Single optimistic update- const trns = { ...(items.value ?? {}) }- for (const id of trnsIds)- delete trns[id]- setTrns(trns)-- if (isDemo.value)- return-- // Batch offline queue- logger.log(`optimistic batch delete: ${trnsIds.length} trns`)- if (!isReplaying()) {- for (const id of trnsIds)- pushOfflineOp({ entity: 'trns', id, type: 'delete' })- }-- const { api, client } = useConvexClientWithApi()- const convexIds = trnsIds.filter(id => !isLocalId(id)).map(id => asConvexId<'trns'>(id))-- if (convexIds.length > 0) {- return handleMutationResult({- action: 'delete',- entity: 'trns',- errorMessage: 'trns.errors.deleteFailed',- id: trnsIds,- mutation: client.mutation(api.trns.removeBatch, { ids: convexIds }),- })- }- else {- // All frontend IDs — just clean up offline queue- removeOfflineOps('trns', trnsIds)- }- }-/*** Remove trns from store only (optimistic UI cleanup).* Does NOT fire mutations or push to offline queue.@@ -418,7 +380,6 @@ export const useTrnsStore = defineStore('trns', () => {cancelPersist: () => debouncedPersist.cancel?.(),computeTrnItem,deleteTrn,- deleteTrnsByIds,getRange,getStoreTrnsIds,hasItems,diff --git a/app/components/wallets/useWalletsStore.test.ts b/app/components/wallets/useWalletsStore.test.tsindex 6365de15..ca0f5a2f 100644--- a/app/components/wallets/useWalletsStore.test.ts+++ b/app/components/wallets/useWalletsStore.test.ts@@ -32,7 +32,6 @@ vi.stubGlobal('useConvexClientWithApi', () => ({const removeTrnsFromStoreMock = vi.fn()vi.mock('~/components/trns/useTrnsStore', () => ({useTrnsStore: () => ({- deleteTrnsByIds: vi.fn(),getStoreTrnsIds: () => [],items: {},removeTrnsFromStore: removeTrnsFromStoreMock,diff --git a/convex/trns.ts b/convex/trns.tsindex 6eab10d0..5543a89a 100644--- a/convex/trns.ts+++ b/convex/trns.ts@@ -7,7 +7,7 @@ import type { MutationCtx } from './_generated/server'import { internal } from './_generated/api'import { mutation, query } from './_generated/server'import { getAuthUser, getOwnEntity, requireAuthUser, TrnType } from './shared'-import { addTrnToHash, fnv1aNum, removeTrnFromHash, removeTrnsFromHash } from './trnsHash'+import { addTrnToHash, fnv1aNum, removeTrnFromHash } from './trnsHash'async function validateTrnFields(ctx: MutationCtx, args: Record<string, any>, userId: string) {if (args.type === TrnType.Transfer) {@@ -204,22 +204,3 @@ export const remove = mutation({},})-const BATCH_LIMIT = 500--export const removeBatch = mutation({- args: { ids: v.array(v.id('trns')) },- handler: async (ctx, { ids }) => {- if (ids.length > BATCH_LIMIT)- throw new Error(`Batch size exceeds limit of ${BATCH_LIMIT}`)-- const user = await requireAuthUser(ctx)- const deletedIds: string[] = []- for (const id of ids) {- const deleted = await removeUserTrn(ctx, id, user._id)- if (deleted)- deletedIds.push(id)- }- if (deletedIds.length)- await removeTrnsFromHash(ctx, user._id, deletedIds)- },-})