[FSSDK-11638] cleanups in event processing by raju-opti · Pull Request #1073 · optimizely/javascript-sdk
Pull Request Overview
This PR refactors how user events are built by introducing a generic buildBaseEvent helper, removes legacy V1 log builders, updates tests to use the unified batch builder, and adds a caching check in the batch processor.
- Extracted common event fields into a new
buildBaseEventfunction and updatedbuildImpressionEvent/buildConversionEventto use it - Removed
buildImpressionEventV1/buildConversionEventV1fromlog_event.tsand revised specs to targetmakeEventBatch - Added an early-return cache in
BatchEventProcessor.readEventCountInStoreto prevent redundant store reads
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib/event_processor/event_builder/user_event.ts | Refactored user events to use a generic BaseUserEvent<T> and buildBaseEvent helper |
| lib/event_processor/event_builder/log_event.ts | Deleted legacy V1 event builders |
| lib/event_processor/event_builder/log_event.spec.ts | Updated tests to call makeEventBatch and renamed suite |
| lib/event_processor/batch_event_processor.ts | Added a guard to skip store lookup when eventCountInStore is already set |
Comments suppressed due to low confidence (3)
lib/event_processor/event_builder/user_event.ts:112
- [nitpick] Consider adding a JSDoc comment to
buildBaseEventto clarify its purpose and parameters for future maintainers.
const buildBaseEvent = <T extends EventType>({
lib/event_processor/event_builder/user_event.ts:47
- [nitpick] If
EventTypeis intended for reuse outside this module, consider exporting it (export type EventType) to improve discoverability.
type EventType = 'impression' | 'conversion';
lib/event_processor/event_builder/user_event.ts:146
- [nitpick] The new
buildImpressionEventandbuildConversionEventfunctions rely onbuildBaseEvent; consider adding direct unit tests to cover their output structure.