1- const EventsFactory = require ( '../models /eventsFactory' ) ;
1+ const getEventsFactory = require ( './helpers /eventsFactory' ) . default ;
22const sendPersonalNotification = require ( '../utils/personalNotifications' ) . default ;
33
4- /**
5- * Returns a per-request, per-project EventsFactory instance
6- * Uses context.eventsFactoryCache to memoize by projectId
7- *
8- * @param {ResolverContextBase } context - resolver context
9- * @param {string } projectId - project id to get EventsFactory instance for
10- * @returns {EventsFactory } - EventsFactory instance bound to a specific project object
11- */
12- function getEventsFactoryForProjectId ( context , projectId ) {
13- const cache = context . eventsFactoryCache || ( context . eventsFactoryCache = new Map ( ) ) ;
14- const cacheKey = projectId . toString ( ) ;
15-
16- if ( ! cache . has ( cacheKey ) ) {
17- cache . set ( cacheKey , new EventsFactory ( projectId ) ) ;
18- }
19-
20- return cache . get ( cacheKey ) ;
21- }
22-
234/**
245 * See all types and fields here {@see ../typeDefs/event.graphql}
256 */
@@ -48,7 +29,7 @@ module.exports = {
4829 * @return {RepetitionsPortion }
4930 */
5031 async repetitionsPortion ( { projectId, originalEventId } , { limit, cursor } , context ) {
51- const factory = getEventsFactoryForProjectId ( context , projectId ) ;
32+ const factory = getEventsFactory ( context , projectId ) ;
5233
5334 return factory . getEventRepetitions ( originalEventId , limit , cursor ) ;
5435 } ,
@@ -103,7 +84,7 @@ module.exports = {
10384 * @returns {Promise<ProjectChartItem[]> }
10485 */
10586 async chartData ( { projectId, groupHash } , { days, timezoneOffset } , context ) {
106- const factory = getEventsFactoryForProjectId ( context , projectId ) ;
87+ const factory = getEventsFactory ( context , projectId ) ;
10788
10889 return factory . findChartData ( days , timezoneOffset , groupHash ) ;
10990 } ,
@@ -116,7 +97,7 @@ module.exports = {
11697 * @returns {Promise<Release> }
11798 */
11899 async release ( { projectId, id : eventId } , _args , context ) {
119- const factory = getEventsFactoryForProjectId ( context , projectId ) ;
100+ const factory = getEventsFactory ( context , projectId ) ;
120101 const release = await factory . getEventRelease ( eventId ) ;
121102
122103 return release ;
@@ -133,7 +114,7 @@ module.exports = {
133114 * @return {Promise<boolean> }
134115 */
135116 async visitEvent ( _obj , { projectId, eventId } , { user, ...context } ) {
136- const factory = getEventsFactoryForProjectId ( context , projectId ) ;
117+ const factory = getEventsFactory ( context , projectId ) ;
137118
138119 const { result } = await factory . visitEvent ( eventId , user . id ) ;
139120
@@ -150,7 +131,7 @@ module.exports = {
150131 * @return {Promise<boolean> }
151132 */
152133 async toggleEventMark ( _obj , { project, eventId, mark } , context ) {
153- const factory = getEventsFactoryForProjectId ( context , project ) ;
134+ const factory = getEventsFactory ( context , project ) ;
154135
155136 const { result } = await factory . toggleEventMark ( eventId , mark ) ;
156137
@@ -175,7 +156,7 @@ module.exports = {
175156 */
176157 async updateAssignee ( _obj , { input } , { factories, user, ...context } ) {
177158 const { projectId, eventId, assignee } = input ;
178- const factory = getEventsFactoryForProjectId ( context , projectId ) ;
159+ const factory = getEventsFactory ( context , projectId ) ;
179160
180161 const userExists = await factories . usersFactory . findById ( assignee ) ;
181162
@@ -226,7 +207,7 @@ module.exports = {
226207 */
227208 async removeAssignee ( _obj , { input } , context ) {
228209 const { projectId, eventId } = input ;
229- const factory = getEventsFactoryForProjectId ( context , projectId ) ;
210+ const factory = getEventsFactory ( context , projectId ) ;
230211
231212 const { result } = await factory . updateAssignee ( eventId , '' ) ;
232213
0 commit comments