diff --git a/src/modules/feeds/domain/services/FeedService.ts b/src/modules/feeds/domain/services/FeedService.ts index 57600d90..3b976809 100644 --- a/src/modules/feeds/domain/services/FeedService.ts +++ b/src/modules/feeds/domain/services/FeedService.ts @@ -46,9 +46,8 @@ export class FeedService implements DomainService { // Update existing activity by merging collections recentActivity.mergeCollections(collectionIds); - const updateResult = await this.feedRepository.updateActivity( - recentActivity, - ); + const updateResult = + await this.feedRepository.updateActivity(recentActivity); if (updateResult.isErr()) { return err( diff --git a/src/modules/feeds/infrastructure/repositories/mappers/FeedActivityMapper.ts b/src/modules/feeds/infrastructure/repositories/mappers/FeedActivityMapper.ts index b05eba27..b34f6de2 100644 --- a/src/modules/feeds/infrastructure/repositories/mappers/FeedActivityMapper.ts +++ b/src/modules/feeds/infrastructure/repositories/mappers/FeedActivityMapper.ts @@ -83,7 +83,7 @@ export class FeedActivityMapper { public static toPersistence(activity: FeedActivity): FeedActivityDTO { let cardId: string | undefined; - + // Extract cardId for CARD_COLLECTED activities if (activity.cardCollected) { const metadata = activity.metadata as CardCollectedMetadata; diff --git a/src/modules/feeds/infrastructure/repositories/schema/feedActivity.sql.ts b/src/modules/feeds/infrastructure/repositories/schema/feedActivity.sql.ts index 9eb04a2b..f561eb5a 100644 --- a/src/modules/feeds/infrastructure/repositories/schema/feedActivity.sql.ts +++ b/src/modules/feeds/infrastructure/repositories/schema/feedActivity.sql.ts @@ -6,7 +6,6 @@ import { uuid, index, } from 'drizzle-orm/pg-core'; -import { sql } from 'drizzle-orm'; export const feedActivities = pgTable( 'feed_activities', @@ -50,8 +49,5 @@ export const feedActivities = pgTable( ), // Index for card-based queries cardIdIdx: index('feed_activities_card_id_idx').on(table.cardId), - // GIN index for collection queries in JSONB - collectionsGinIdx: index('feed_activities_collections_gin_idx') - .using('gin', sql`(metadata->'collectionIds')`), }), ); diff --git a/src/modules/feeds/tests/infrastructure/DrizzleFeedRepository.integration.test.ts b/src/modules/feeds/tests/infrastructure/DrizzleFeedRepository.integration.test.ts index 2440002d..50829e97 100644 --- a/src/modules/feeds/tests/infrastructure/DrizzleFeedRepository.integration.test.ts +++ b/src/modules/feeds/tests/infrastructure/DrizzleFeedRepository.integration.test.ts @@ -311,7 +311,7 @@ describe('DrizzleFeedRepository', () => { describe('deduplication and merging', () => { it('should find recent card collected activity within time window', async () => { const baseTime = new Date(); - + // Create an activity 1 minute ago const recentActivity = FeedActivity.createCardCollected( curatorId, @@ -340,7 +340,7 @@ describe('DrizzleFeedRepository', () => { it('should not find activity outside time window', async () => { const baseTime = new Date(); - + // Create an activity 3 minutes ago const oldActivity = FeedActivity.createCardCollected( curatorId, @@ -365,7 +365,7 @@ describe('DrizzleFeedRepository', () => { it('should not find activity for different actor', async () => { const baseTime = new Date(); - + // Create an activity for different actor const activity = FeedActivity.createCardCollected( anotherCuratorId, // different actor @@ -390,7 +390,7 @@ describe('DrizzleFeedRepository', () => { it('should not find activity for different card', async () => { const baseTime = new Date(); - + // Create an activity for different card const activity = FeedActivity.createCardCollected( curatorId, @@ -424,7 +424,8 @@ describe('DrizzleFeedRepository', () => { await feedRepository.addActivity(activity); // Merge new collections - const newCollection = CollectionId.createFromString('new-collection').unwrap(); + const newCollection = + CollectionId.createFromString('new-collection').unwrap(); activity.mergeCollections([newCollection]); // Update the activity @@ -432,7 +433,9 @@ describe('DrizzleFeedRepository', () => { expect(updateResult.isOk()).toBe(true); // Retrieve and verify the updated activity - const retrievedResult = await feedRepository.findById(activity.activityId); + const retrievedResult = await feedRepository.findById( + activity.activityId, + ); const retrievedActivity = retrievedResult.unwrap(); expect(retrievedActivity?.metadata.collectionIds).toEqual([ @@ -458,7 +461,9 @@ describe('DrizzleFeedRepository', () => { await feedRepository.updateActivity(activity); // Retrieve and verify no duplicates - const retrievedResult = await feedRepository.findById(activity.activityId); + const retrievedResult = await feedRepository.findById( + activity.activityId, + ); const retrievedActivity = retrievedResult.unwrap(); expect(retrievedActivity?.metadata.collectionIds).toEqual([ @@ -469,7 +474,7 @@ describe('DrizzleFeedRepository', () => { it('should find most recent activity when multiple exist', async () => { const baseTime = new Date(); - + // Create older activity (2 minutes ago) const olderActivity = FeedActivity.createCardCollected( curatorId, diff --git a/src/shared/infrastructure/database/migrations/meta/0012_snapshot.json b/src/shared/infrastructure/database/migrations/meta/0012_snapshot.json index 5acf2702..74eeb3a7 100644 --- a/src/shared/infrastructure/database/migrations/meta/0012_snapshot.json +++ b/src/shared/infrastructure/database/migrations/meta/0012_snapshot.json @@ -251,12 +251,8 @@ "name": "cards_parent_card_id_cards_id_fk", "tableFrom": "cards", "tableTo": "cards", - "columnsFrom": [ - "parent_card_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["parent_card_id"], + "columnsTo": ["id"], "onDelete": "no action", "onUpdate": "no action" }, @@ -264,12 +260,8 @@ "name": "cards_via_card_id_cards_id_fk", "tableFrom": "cards", "tableTo": "cards", - "columnsFrom": [ - "via_card_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["via_card_id"], + "columnsTo": ["id"], "onDelete": "no action", "onUpdate": "no action" }, @@ -277,12 +269,8 @@ "name": "cards_published_record_id_published_records_id_fk", "tableFrom": "cards", "tableTo": "published_records", - "columnsFrom": [ - "published_record_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["published_record_id"], + "columnsTo": ["id"], "onDelete": "no action", "onUpdate": "no action" } @@ -414,12 +402,8 @@ "name": "collection_cards_collection_id_collections_id_fk", "tableFrom": "collection_cards", "tableTo": "collections", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["collection_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -427,12 +411,8 @@ "name": "collection_cards_card_id_cards_id_fk", "tableFrom": "collection_cards", "tableTo": "cards", - "columnsFrom": [ - "card_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["card_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -440,12 +420,8 @@ "name": "collection_cards_via_card_id_cards_id_fk", "tableFrom": "collection_cards", "tableTo": "cards", - "columnsFrom": [ - "via_card_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["via_card_id"], + "columnsTo": ["id"], "onDelete": "no action", "onUpdate": "no action" }, @@ -453,12 +429,8 @@ "name": "collection_cards_published_record_id_published_records_id_fk", "tableFrom": "collection_cards", "tableTo": "published_records", - "columnsFrom": [ - "published_record_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["published_record_id"], + "columnsTo": ["id"], "onDelete": "no action", "onUpdate": "no action" } @@ -498,12 +470,8 @@ "name": "collection_collaborators_collection_id_collections_id_fk", "tableFrom": "collection_collaborators", "tableTo": "collections", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["collection_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" } @@ -619,12 +587,8 @@ "name": "collections_published_record_id_published_records_id_fk", "tableFrom": "collections", "tableTo": "published_records", - "columnsFrom": [ - "published_record_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["published_record_id"], + "columnsTo": ["id"], "onDelete": "no action", "onUpdate": "no action" } @@ -723,12 +687,8 @@ "name": "library_memberships_card_id_cards_id_fk", "tableFrom": "library_memberships", "tableTo": "cards", - "columnsFrom": [ - "card_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["card_id"], + "columnsTo": ["id"], "onDelete": "cascade", "onUpdate": "no action" }, @@ -736,12 +696,8 @@ "name": "library_memberships_published_record_id_published_records_id_fk", "tableFrom": "library_memberships", "tableTo": "published_records", - "columnsFrom": [ - "published_record_id" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["published_record_id"], + "columnsTo": ["id"], "onDelete": "no action", "onUpdate": "no action" } @@ -749,10 +705,7 @@ "compositePrimaryKeys": { "library_memberships_card_id_user_id_pk": { "name": "library_memberships_card_id_user_id_pk", - "columns": [ - "card_id", - "user_id" - ] + "columns": ["card_id", "user_id"] } }, "uniqueConstraints": {}, @@ -1275,12 +1228,8 @@ "name": "auth_refresh_tokens_user_did_users_id_fk", "tableFrom": "auth_refresh_tokens", "tableTo": "users", - "columnsFrom": [ - "user_did" - ], - "columnsTo": [ - "id" - ], + "columnsFrom": ["user_did"], + "columnsTo": ["id"], "onDelete": "no action", "onUpdate": "no action" } @@ -1340,4 +1289,4 @@ "schemas": {}, "tables": {} } -} \ No newline at end of file +} diff --git a/src/shared/infrastructure/database/migrations/meta/_journal.json b/src/shared/infrastructure/database/migrations/meta/_journal.json index f7a6a923..cc5c7bdf 100644 --- a/src/shared/infrastructure/database/migrations/meta/_journal.json +++ b/src/shared/infrastructure/database/migrations/meta/_journal.json @@ -94,4 +94,4 @@ "breakpoints": true } ] -} \ No newline at end of file +}