From 170b0c781baad81286768c2e38e0b7c60f9002ff Mon Sep 17 00:00:00 2001 From: vishwab1 Date: Wed, 9 Sep 2026 12:57:18 +0530 Subject: [PATCH] fix: batch Nikshay villages request to avoid oversized GET query string Selecting all facilities across multiple Nikshay TUs (e.g. a full district) could push 1000+ facility IDs into a single comma-separated GET query string, exceeding the ~8KB request-line limit enforced by proxies/Tomcat and causing a 400 before the request ever reached the controller (observed as a 400/OK Http failure on /nikshay/location/villages). getNikshayVillages now splits facilityIDs into batches of 200, fetches them in parallel via forkJoin, and merges the responses into the same { data: [...] } shape callers already expect, so no changes were needed at either call site in work-location-mapping.component.ts. Co-Authored-By: Claude Sonnet 5 --- .../services/work-location-mapping.service.ts | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/app/app-provider-admin/provider-admin/activities/services/work-location-mapping.service.ts b/src/app/app-provider-admin/provider-admin/activities/services/work-location-mapping.service.ts index e28a507..073198a 100644 --- a/src/app/app-provider-admin/provider-admin/activities/services/work-location-mapping.service.ts +++ b/src/app/app-provider-admin/provider-admin/activities/services/work-location-mapping.service.ts @@ -21,9 +21,18 @@ */ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; +import { forkJoin, of } from 'rxjs'; +import { map } from 'rxjs/operators'; import { ConfigService } from 'src/app/core/services/config/config.service'; import { environment } from 'src/environments/environment'; +// A "select all" facility pick (e.g. every facility under several Nikshay +// TUs) can put 1000+ IDs on this GET's query string, which blows past the +// server/proxy request-line limit (~8KB) and comes back as a 400. The +// backend only exposes a comma-separated-param GET (no POST/body variant), +// so batch client-side instead of widening a single request. +const NIKSHAY_VILLAGES_BATCH_SIZE = 200; + /** * Author: krishna Gunti ( 378952 ) * Date: 05-03-2018 @@ -152,8 +161,29 @@ export class WorkLocationMapping { } getNikshayVillages(facilityIDs: any[]) { - return this.http.get( - `${environment.nikshayVillages_url}?facilityIDs=${facilityIDs.join(',')}`, + const ids = (facilityIDs || []).filter( + (id) => id !== null && id !== undefined, + ); + if (!ids.length) { + return of({ data: [] }); + } + const chunks: any[][] = []; + for (let i = 0; i < ids.length; i += NIKSHAY_VILLAGES_BATCH_SIZE) { + chunks.push(ids.slice(i, i + NIKSHAY_VILLAGES_BATCH_SIZE)); + } + return forkJoin( + chunks.map((chunk) => + this.http.get( + `${environment.nikshayVillages_url}?facilityIDs=${chunk.join(',')}`, + ), + ), + ).pipe( + map((responses: any[]) => ({ + data: responses.reduce( + (acc: any[], r: any) => acc.concat(r?.data || []), + [], + ), + })), ); }