tango-app-api-audit 3.6.52 → 3.6.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.6.52",
3
+ "version": "3.6.54",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -933,7 +933,8 @@ export async function getFilterData( msg, user ) {
933
933
  ( item ) =>
934
934
  item.temp_ids < 20000 &&
935
935
  item.temp_ids > 0 &&
936
- item.person_status === '',
936
+ item.person_status === '' &&
937
+ item.query_status !== '',
937
938
  );
938
939
  const finalResult = await filterData.map( ( i ) => {
939
940
  return { ...i, img: i.index.concat( '_', i.temp_ids ) };
@@ -3275,7 +3275,8 @@ export async function getConversationDetails( req, res ) {
3275
3275
  };
3276
3276
 
3277
3277
  // Format metrics results with sequential time allocation
3278
- const metricsData = source?.cohort_analysis_results?.[0]?.metrics_results || [];
3278
+ const matchedCohort = source?.cohort_analysis_results?.find( ( c ) => c.cohortId === 'cohort_11_1ddea945-ff3a-4c11-95a9-bb425ca927de' );
3279
+ const metricsData = matchedCohort?.metrics_results || [];
3279
3280
 
3280
3281
  // Calculate sequential times for detected metrics
3281
3282
  let currentSeconds = 0;
@@ -150,13 +150,11 @@ export async function mapCustomer( sourceMappingData, customerData ) {
150
150
  try {
151
151
  const filterCustomerData = await filteredCustomerMap( customerData );
152
152
  logger.info( { filterCustomerData: filterCustomerData } );
153
- const chunkedMappingData = await chunkArray( sourceMappingData, 10 );
154
-
155
- const promises = chunkedMappingData.map( async ( chunk ) => {
156
- return mapFunction( chunk, filterCustomerData );
157
- } );
158
- const mappedArrays = await Promise.all( promises );
159
- return mappedArrays.flat();
153
+ // Build the lookup once, then retag every row in a single pass. This is
154
+ // O(rows + mappedIds) and scales for concurrent submissions, versus the old
155
+ // O(customers x mappedIds x rows) scan that also re-read its own mutations.
156
+ const customerMap = buildCustomerMap( filterCustomerData );
157
+ return mapFunction( sourceMappingData, customerMap );
160
158
  } catch ( error ) {
161
159
  logger.error( { error: error, type: 'mapCustomer' } );
162
160
  return error;
@@ -167,22 +165,39 @@ const filteredCustomerMap = async ( data ) => {
167
165
  return data.filter( ( map ) => map.count >= 1 );
168
166
  };
169
167
 
170
- const mapFunction = async ( chunkData, filterData ) => {
168
+ // Lookup of original cluster id (child img_name) -> the customer it was tagged
169
+ // into. Last write wins if the same id is referenced by more than one group, so
170
+ // the result is deterministic regardless of customer order.
171
+ const buildCustomerMap = ( filterData ) => {
172
+ const customerMap = new Map();
171
173
  for ( const data of filterData ) {
172
- const mappedIds = data.mappedid;
173
- if ( data?.mappedid ) {
174
- for ( const mappedId of mappedIds ) {
175
- chunkData.find( ( item ) => {
176
- if ( mappedId.img_name === item.temp_ids ) {
177
- item.temp_ids = data.img_name;
178
- ( mappedId.img_name !== data.img_name ) ? item.query_status = '' : null;
179
- item.demographic = data.demographic || '';
180
- }
181
- } );
182
- }
174
+ if ( !data?.mappedid ) continue;
175
+ for ( const mappedId of data.mappedid ) {
176
+ customerMap.set( mappedId.img_name, {
177
+ parentId: data.img_name,
178
+ demographic: data.demographic || '',
179
+ // The chosen representative (img_name === parent) keeps its query flag so
180
+ // it resurfaces in reaudit; every other merged image is cleared so it does
181
+ // not (query_status is the reaudit gate in getFilterData / getAuditFilterData).
182
+ isChild: mappedId.img_name !== data.img_name,
183
+ } );
183
184
  }
184
185
  }
185
- return chunkData;
186
+ return customerMap;
187
+ };
188
+
189
+ // Single pass over the master-json rows. Each row's ORIGINAL temp_ids is read
190
+ // exactly once and reassigned to its customer's parent id, so every row sharing
191
+ // a temp_ids is retagged and the retag never feeds back into later lookups.
192
+ const mapFunction = ( personData, customerMap ) => {
193
+ for ( const item of personData ) {
194
+ const mapped = customerMap.get( item.temp_ids );
195
+ if ( !mapped ) continue;
196
+ item.temp_ids = mapped.parentId;
197
+ item.query_status = mapped.isChild ? '' : item.query_status;
198
+ item.demographic = mapped.demographic;
199
+ }
200
+ return personData;
186
201
  };
187
202
 
188
203
  export async function isAuditInputFolderExist( req, res, next ) {
@@ -344,7 +359,8 @@ export async function getAuditFilterData( data ) {
344
359
  ( item ) =>
345
360
  item.temp_ids < 20000 &&
346
361
  item.temp_ids > 0 &&
347
- item.person_status === '',
362
+ item.person_status === '' &&
363
+ item.query_status !== '',
348
364
  );
349
365
  const finalResult = await filterData.map( ( i ) => {
350
366
  return { ...i, img: i.index.concat( '_', i.temp_ids ) };