feat: add lightweight /api/routes/lite endpoint for route selectors
Avoid loading full route data (channels, decision snapshots) when Settings page only needs basic route info for selectors.
This commit is contained in:
@@ -379,6 +379,17 @@ function parseBatchRouteWideDecisionRouteIds(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function tokensRoutes(app: FastifyInstance) {
|
export async function tokensRoutes(app: FastifyInstance) {
|
||||||
|
// List routes with basic info only (lightweight for selectors)
|
||||||
|
app.get('/api/routes/lite', async () => {
|
||||||
|
return await db.select({
|
||||||
|
id: schema.tokenRoutes.id,
|
||||||
|
modelPattern: schema.tokenRoutes.modelPattern,
|
||||||
|
displayName: schema.tokenRoutes.displayName,
|
||||||
|
displayIcon: schema.tokenRoutes.displayIcon,
|
||||||
|
enabled: schema.tokenRoutes.enabled,
|
||||||
|
}).from(schema.tokenRoutes).all();
|
||||||
|
});
|
||||||
|
|
||||||
// List all routes
|
// List all routes
|
||||||
app.get('/api/routes', async () => {
|
app.get('/api/routes', async () => {
|
||||||
const routes = await db.select().from(schema.tokenRoutes).all();
|
const routes = await db.select().from(schema.tokenRoutes).all();
|
||||||
|
|||||||
@@ -273,6 +273,7 @@ export const api = {
|
|||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
getRoutes: () => request('/api/routes'),
|
getRoutes: () => request('/api/routes'),
|
||||||
|
getRoutesLite: () => request('/api/routes/lite'),
|
||||||
addRoute: (data: any) => request('/api/routes', { method: 'POST', body: JSON.stringify(data) }),
|
addRoute: (data: any) => request('/api/routes', { method: 'POST', body: JSON.stringify(data) }),
|
||||||
updateRoute: (id: number, data: any) => request(`/api/routes/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
|
updateRoute: (id: number, data: any) => request(`/api/routes/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
|
||||||
deleteRoute: (id: number) => request(`/api/routes/${id}`, { method: 'DELETE' }),
|
deleteRoute: (id: number) => request(`/api/routes/${id}`, { method: 'DELETE' }),
|
||||||
|
|||||||
@@ -352,7 +352,7 @@ export default function Settings() {
|
|||||||
const loadRouteSelectorRoutes = async () => {
|
const loadRouteSelectorRoutes = async () => {
|
||||||
setSelectorLoading(true);
|
setSelectorLoading(true);
|
||||||
try {
|
try {
|
||||||
const rows = await api.getRoutes();
|
const rows = await api.getRoutesLite();
|
||||||
setSelectorRoutes((Array.isArray(rows) ? rows : []).map((row: any) => ({
|
setSelectorRoutes((Array.isArray(rows) ? rows : []).map((row: any) => ({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
modelPattern: row.modelPattern,
|
modelPattern: row.modelPattern,
|
||||||
@@ -374,7 +374,7 @@ export default function Settings() {
|
|||||||
api.getAuthInfo(),
|
api.getAuthInfo(),
|
||||||
api.getRuntimeSettings(),
|
api.getRuntimeSettings(),
|
||||||
api.getDownstreamApiKeys(),
|
api.getDownstreamApiKeys(),
|
||||||
api.getRoutes(),
|
api.getRoutesLite(),
|
||||||
api.getRuntimeDatabaseConfig(),
|
api.getRuntimeDatabaseConfig(),
|
||||||
]);
|
]);
|
||||||
setMaskedToken(authInfo.masked || '****');
|
setMaskedToken(authInfo.masked || '****');
|
||||||
|
|||||||
Reference in New Issue
Block a user