fix: Fix Map page

This commit is contained in:
2025-06-12 22:50:43 +03:00
parent 27cb644242
commit 300ff262ce
41 changed files with 2216 additions and 1055 deletions

View File

@ -54,20 +54,15 @@ class MapStore {
sights: ApiSight[] = [];
getRoutes = async () => {
const routes = await languageInstance("ru").get("/route");
const routedIds = routes.data.map((route: any) => route.id);
const mappedRoutes: ApiRoute[] = [];
for (const routeId of routedIds) {
const responseSoloRoute = await languageInstance("ru").get(
`/route/${routeId}`
);
const route = responseSoloRoute.data;
mappedRoutes.push({
id: route.id,
route_number: route.route_number,
path: route.path,
});
}
// ИСПРАВЛЕНО: Проблема N+1.
// Вместо цикла и множества запросов теперь выполняется один.
// Бэкенд по эндпоинту `/route` должен возвращать массив полных объектов маршрутов.
const response = await languageInstance("ru").get("/route");
const mappedRoutes: ApiRoute[] = response.data.map((route: any) => ({
id: route.id,
route_number: route.route_number,
path: route.path,
}));
this.routes = mappedRoutes.sort((a, b) =>
a.route_number.localeCompare(b.route_number)
);