44 * Path: $(countly dir)/bin/scripts/export-data
55 * Command: node setting_limits_and_real_values.js
66 */
7-
87const fs = require ( 'fs' ) ;
98const crypto = require ( 'crypto' ) ;
109const common = require ( '../../../api/utils/common.js' ) ;
@@ -20,10 +19,10 @@ const DEFAULT_LIMITS = {
2019 view_name_limit : 128 ,
2120 view_segment_limit : 100 ,
2221 view_segment_value_limit : 10 ,
23- custom_prop_limit : 20 ,
22+ //custom_prop_limit: 20,
23+ custom_property_limit : 20 ,
2424 custom_prop_value_limit : 50 ,
2525} ;
26-
2726Promise . all ( [ pluginManager . dbConnection ( "countly" ) , pluginManager . dbConnection ( "countly_drill" ) ] ) . then ( async function ( [ countlyDb , drillDb ] ) {
2827 console . log ( "Connected to databases..." ) ;
2928 common . db = countlyDb ;
@@ -36,21 +35,17 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
3635 else {
3736 // WRITE START OF ARRAY
3837 WriteStream . write ( '[\n' , 'utf8' ) ;
39-
4038 // GETTING DATA FOR SET LIMITS FOR EVENTS, VIEWS, AND CUSTOM PROPERTIES
4139 var pluginsCollectionPlugins = await countlyDb . collection ( "plugins" ) . findOne ( { "_id" : 'plugins' } ) ;
42-
4340 // LOOP APPS FOR EACH REQUIREMENT
4441 for ( let i = 0 ; i < apps . length ; i ++ ) {
4542 var app = apps [ i ] ;
4643 console . log ( i + 1 , ") Processing app:" , app . name ) ;
47-
4844 try {
4945 var app_results = { "App Name" : app . name } ,
5046 defaultVal ,
5147 realVal ,
5248 currentVal ;
53-
5449 // SETTING UP CURRENT SET LIMITS PER APP
5550 var appsCollectionPerApp = await countlyDb . collection ( "apps" ) . findOne ( { "_id" : common . db . ObjectID ( app . _id ) } ) ;
5651 var CURRENT_LIMITS = {
@@ -61,10 +56,10 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
6156 view_name_limit : pluginsCollectionPlugins ?. views ?. view_name_limit || DEFAULT_LIMITS . view_name_limit ,
6257 view_segment_limit : pluginsCollectionPlugins ?. views ?. segment_limit || DEFAULT_LIMITS . view_segment_limit ,
6358 view_segment_value_limit : pluginsCollectionPlugins ?. views ?. segment_value_limit || DEFAULT_LIMITS . view_segment_value_limit ,
64- custom_prop_limit : pluginsCollectionPlugins ?. users ?. custom_prop_limit || DEFAULT_LIMITS . custom_prop_limit ,
59+ //custom_prop_limit: pluginsCollectionPlugins?.users?.custom_prop_limit || DEFAULT_LIMITS.custom_prop_limit,
60+ custom_property_limit : pluginsCollectionPlugins ?. drill ?. custom_property_limit || DEFAULT_LIMITS . custom_property_limit ,
6561 custom_prop_value_limit : pluginsCollectionPlugins ?. users ?. custom_set_limit || DEFAULT_LIMITS . custom_prop_value_limit ,
6662 } ;
67-
6863 // GETTING REAL DATA PER APP
6964 var eventsCollectionPerApp = await countlyDb . collection ( "events" ) . findOne ( { "_id" : common . db . ObjectID ( app . _id ) } ) ;
7065 var viewsCountsPerApp = await countlyDb . collection ( "app_viewsmeta" + app . _id ) . countDocuments ( ) ;
@@ -140,46 +135,34 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
140135 catch ( err ) {
141136 console . log ( "Mongodb operation failed for app: " , app . name , err ) ;
142137 }
143-
144138 // EVENT KEYS
145139 defaultVal = DEFAULT_LIMITS . event_limit ;
146-
147140 currentVal = CURRENT_LIMITS . event_limit ;
148-
149141 let realEvents = eventsCollectionPerApp ?. list || [ ] ;
150142 realVal = realEvents . length ;
151-
152143 app_results [ 'Event Keys' ] = { "default" : defaultVal , "set" : currentVal , "real" : realVal } ;
153-
154144 // SEGMENTS IN ONE EVENT
155145 defaultVal = DEFAULT_LIMITS . event_segment_limit ;
156-
157146 currentVal = CURRENT_LIMITS . event_segment_limit ;
158-
159147 let eventSegments = eventsCollectionPerApp && eventsCollectionPerApp . segments || { } ;
160148 realVal = Object . entries ( eventSegments )
161149 . sort ( ( a , b ) => b [ 1 ] . length - a [ 1 ] . length )
162150 . reduce ( ( acc , [ key , value ] ) => {
163151 acc [ key ] = value . length ;
164152 return acc ;
165153 } , { } ) ;
166-
167154 app_results [ 'Event Segments' ] = { "default" : defaultVal , "set" : currentVal , "real" : realVal } ;
168-
169155 // UNIQUE EVENT SEGMENT VALUES FOR 1 SEGMENT
170156 defaultVal = DEFAULT_LIMITS . event_segment_value_limit ;
171-
172157 currentVal = CURRENT_LIMITS . event_segment_value_limit ;
173-
174158 realVal = { } ;
175159 await Promise . all ( realEvents . map ( async ( event ) => {
176160 var shortEventName = common . fixEventKey ( event ) ;
177- var eventCollectionName = "events" + crypto . createHash ( 'sha1' ) . update ( shortEventName + app . _id ) . digest ( 'hex' ) ;
178-
161+ var hash = crypto . createHash ( 'sha1' ) . update ( shortEventName + app . _id ) . digest ( 'hex' ) ;
162+ var eventCollectionName = "events_data" ;
179163 try {
180164 var regexes = [
181- "^no-segment_2023:0.*" ,
182- "^no-segment_2024:0.*"
165+ "^" + app . _id + "_" + hash + "_no-segment_2025:0.*"
183166 ] ;
184167 var eventsSegmentsValues = await countlyDb . collection ( eventCollectionName ) . aggregate ( [
185168 {
@@ -218,7 +201,6 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
218201 }
219202 }
220203 ] ) . toArray ( ) ;
221-
222204 // Use reduce to transform array
223205 eventsSegmentsValues = eventsSegmentsValues . reduce ( ( acc , item ) => {
224206 const key = item . meta_v2 . k ;
@@ -228,7 +210,6 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
228210 acc [ key ] += item . meta_v2 . v ;
229211 return acc ;
230212 } , { } ) ;
231-
232213 if ( Object . keys ( eventsSegmentsValues ) . length > 0 ) {
233214 realVal [ event ] = eventsSegmentsValues ;
234215 }
@@ -238,65 +219,45 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
238219 }
239220 } ) ) ;
240221 app_results [ 'Unique Event Segment Values' ] = { "default" : defaultVal , "set" : currentVal , "real" : realVal } ;
241-
242222 // UNIQUE VIEV NAMES
243223 defaultVal = DEFAULT_LIMITS . view_limit ;
244-
245224 currentVal = CURRENT_LIMITS . view_limit ;
246-
247225 realVal = viewsCountsPerApp ;
248-
249226 app_results [ 'Unique View Names' ] = { "default" : defaultVal , "set" : currentVal , "real" : realVal } ;
250-
251227 // VIEW NAME LENGTH LIMIT
252228 defaultVal = DEFAULT_LIMITS . view_name_limit ;
253-
254229 currentVal = CURRENT_LIMITS . view_name_limit ;
255-
256230 realVal = { longestViewName : "" , longestViewLength : 0 } ;
257231 realVal . longestViewName = viewsCollectionPerApp && viewsCollectionPerApp [ 0 ] && viewsCollectionPerApp [ 0 ] ?. view ;
258232 realVal . longestViewLength = viewsCollectionPerApp && viewsCollectionPerApp [ 0 ] && viewsCollectionPerApp [ 0 ] ?. max_length ;
259-
260233 app_results [ 'View Name Length Limit' ] = { "default" : defaultVal , "set" : currentVal , "real" : realVal } ;
261-
262234 // SEGMENTS IN ONE VIEW
263235 defaultVal = DEFAULT_LIMITS . view_segment_limit ;
264-
265236 currentVal = CURRENT_LIMITS . view_segment_limit ;
266-
267237 realVal = viewsSegmentsPerApp && viewsSegmentsPerApp [ 0 ] ?. numberOfSegments || 0 ;
268-
269238 app_results [ 'View Segments' ] = { "default" : defaultVal , "set" : currentVal , "real" : realVal } ;
270-
271239 // VIEW SEGMENT'S UNIQUE VALUES
272240 defaultVal = DEFAULT_LIMITS . view_segment_value_limit ;
273-
274241 currentVal = CURRENT_LIMITS . view_segment_value_limit ;
275-
276242 realVal = viewsSegmentsPerApp && viewsSegmentsPerApp [ 0 ] ?. segments || 0 ;
277243 Object . keys ( realVal ) . forEach ( key => {
278244 if ( realVal [ key ] === 0 ) {
279245 delete realVal [ key ] ;
280246 }
281247 } ) ;
282248 app_results [ 'View Segments Unique Values' ] = { "default" : defaultVal , "set" : currentVal , "real" : realVal } ;
283-
284249 // USER PROPERTIES
285- defaultVal = DEFAULT_LIMITS . custom_prop_limit ;
286-
287- currentVal = CURRENT_LIMITS . custom_prop_limit ;
288-
250+ // defaultVal = DEFAULT_LIMITS.custom_prop_limit;
251+ //currentVal = CURRENT_LIMITS.custom_prop_limit;
252+ defaultVal = DEFAULT_LIMITS . custom_property_limit ;
253+ currentVal = CURRENT_LIMITS . custom_property_limit ;
289254 realVal = customPropsPerApp && customPropsPerApp [ 0 ] ?. customPropertiesCount || 0 ;
290- app_results [ 'Custom User Properties' ] = { "default" : defaultVal , "set" : currentVal , "real" : realVal } ;
291-
255+ app_results [ 'Max user custom properties' ] = { "default" : defaultVal , "set" : currentVal , "real" : realVal } ;
292256 // VALUES IN AN ARRAY FOR ONE USER PROPERTY
293257 defaultVal = DEFAULT_LIMITS . custom_prop_value_limit ;
294-
295258 currentVal = CURRENT_LIMITS . custom_prop_value_limit ;
296-
297259 realVal = valueFieldCounts || undefined ;
298260 app_results [ 'Values In Array For One User Property' ] = { "default" : defaultVal , "set" : currentVal , "real" : realVal } ;
299-
300261 // WRITE RESULTS PER APP TO FILE
301262 WriteStream . write ( JSON . stringify ( app_results , null , 2 ) , 'utf8' ) ;
302263 if ( i + 1 < apps . length ) {
@@ -315,7 +276,6 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
315276 finally {
316277 close ( ) ;
317278 }
318-
319279 async function getAppList ( options ) {
320280 var query = { } ;
321281 if ( app_list && app_list . length > 0 ) {
@@ -325,7 +285,6 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
325285 }
326286 query = { _id : { $in : listed } } ;
327287 }
328-
329288 try {
330289 let apps = await options . db . collection ( "apps" ) . find ( query ) . toArray ( ) ;
331290 return apps ;
@@ -334,9 +293,7 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
334293 console . log ( "Error getting apps: " , err ) ;
335294 return [ ] ;
336295 }
337-
338296 }
339-
340297 function close ( err ) {
341298 if ( err ) {
342299 console . log ( "Error: " , err ) ;
0 commit comments