chore: eliminar código muerto y activar purga del outbox
Auditoría de exports sin uso: - Eliminados: getPhases, getLayers, getTemplate, countRows (repositories), setCursor (redundante: applyBundle escribe el cursor por SQL), y la constante TOKEN_ABILITY (config). getPhases/getTemplate quedaron huérfanos al quitar la pestaña Fases y cambiar el selector de plantillas. - purgeSentOperations existía pero NADIE la llamaba (el outbox acumulaba filas 'sent' sin límite): ahora runSync la invoca al final del ciclo. Sin mocks, TODOs ni simulaciones en el código. Typecheck limpio. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -54,6 +54,3 @@ export const APP_VERSION = '1.0.0';
|
|||||||
|
|
||||||
/** Nombre de la BD SQLite local. */
|
/** Nombre de la BD SQLite local. */
|
||||||
export const DB_NAME = 'avante.db';
|
export const DB_NAME = 'avante.db';
|
||||||
|
|
||||||
/** Ability que el backend exige al token (ver brief §2). */
|
|
||||||
export const TOKEN_ABILITY = 'mobile-sync';
|
|
||||||
|
|||||||
@@ -44,8 +44,6 @@ export async function setMeta(key: string, value: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getCursor = (projectId: number) => getMeta(CURSOR_PREFIX + projectId);
|
export const getCursor = (projectId: number) => getMeta(CURSOR_PREFIX + projectId);
|
||||||
export const setCursor = (projectId: number, serverTime: string) =>
|
|
||||||
setMeta(CURSOR_PREFIX + projectId, serverTime);
|
|
||||||
|
|
||||||
export const getActiveProjectId = async (): Promise<number | null> => {
|
export const getActiveProjectId = async (): Promise<number | null> => {
|
||||||
const v = await getMeta(ACTIVE_PROJECT_KEY);
|
const v = await getMeta(ACTIVE_PROJECT_KEY);
|
||||||
@@ -301,14 +299,6 @@ export async function saveProjectList(projects: Project[]): Promise<void> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPhases(projectId: number): Promise<Phase[]> {
|
|
||||||
const db = await getDb();
|
|
||||||
return db.getAllAsync<Phase>(
|
|
||||||
'SELECT * FROM phases WHERE project_id = ? ORDER BY "order", id',
|
|
||||||
projectId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getIssues(projectId: number): Promise<Issue[]> {
|
export async function getIssues(projectId: number): Promise<Issue[]> {
|
||||||
const db = await getDb();
|
const db = await getDb();
|
||||||
return db.getAllAsync<Issue>(
|
return db.getAllAsync<Issue>(
|
||||||
@@ -322,14 +312,6 @@ export async function getIssue(id: number): Promise<Issue | null> {
|
|||||||
return db.getFirstAsync<Issue>('SELECT * FROM issues WHERE id = ?', id);
|
return db.getFirstAsync<Issue>('SELECT * FROM issues WHERE id = ?', id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getLayers(projectId: number): Promise<Layer[]> {
|
|
||||||
const db = await getDb();
|
|
||||||
return db.getAllAsync<Layer>(
|
|
||||||
'SELECT * FROM layers WHERE project_id = ? ORDER BY name',
|
|
||||||
projectId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Features de un proyecto. `geometry` se devuelve como objeto ya parseado. */
|
/** Features de un proyecto. `geometry` se devuelve como objeto ya parseado. */
|
||||||
export async function getFeatures(projectId: number): Promise<Feature[]> {
|
export async function getFeatures(projectId: number): Promise<Feature[]> {
|
||||||
const db = await getDb();
|
const db = await getDb();
|
||||||
@@ -413,17 +395,6 @@ export async function getFeatureTypes(): Promise<FeatureType[]> {
|
|||||||
return db.getAllAsync<FeatureType>('SELECT * FROM feature_types ORDER BY name');
|
return db.getAllAsync<FeatureType>('SELECT * FROM feature_types ORDER BY name');
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getTemplate(id: number): Promise<Template | null> {
|
|
||||||
const db = await getDb();
|
|
||||||
const row = await db.getFirstAsync<Template & { fields: string | null }>(
|
|
||||||
'SELECT * FROM templates WHERE id = ?',
|
|
||||||
id,
|
|
||||||
);
|
|
||||||
return row
|
|
||||||
? { ...row, fields: row.fields ? (JSON.parse(row.fields) as unknown[]) : [] }
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Media YA sincronizada (con url) para un padre. */
|
/** Media YA sincronizada (con url) para un padre. */
|
||||||
export async function getMediaFor(
|
export async function getMediaFor(
|
||||||
parentEntity: string,
|
parentEntity: string,
|
||||||
@@ -437,11 +408,6 @@ export async function getMediaFor(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function countRows(table: string): Promise<number> {
|
|
||||||
const db = await getDb();
|
|
||||||
const row = await db.getFirstAsync<{ n: number }>(`SELECT COUNT(*) AS n FROM ${table}`);
|
|
||||||
return row?.n ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Aplica el valor del servidor (recibido en un conflicto) a la fila local. */
|
/** Aplica el valor del servidor (recibido en un conflicto) a la fila local. */
|
||||||
export async function applyServerValue(
|
export async function applyServerValue(
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import {
|
|||||||
markMediaError,
|
markMediaError,
|
||||||
markMediaSent,
|
markMediaSent,
|
||||||
PendingOp,
|
PendingOp,
|
||||||
|
purgeSentOperations,
|
||||||
updateOutboxData,
|
updateOutboxData,
|
||||||
} from '../db/outbox';
|
} from '../db/outbox';
|
||||||
|
|
||||||
@@ -232,5 +233,9 @@ export async function runSync(projectId: number): Promise<SyncReport> {
|
|||||||
await pushMedia(report);
|
await pushMedia(report);
|
||||||
await pull(projectId, report);
|
await pull(projectId, report);
|
||||||
|
|
||||||
|
// Housekeeping: descarta del outbox las operaciones ya confirmadas para que
|
||||||
|
// la tabla no crezca sin límite (los conflictos/errores se conservan).
|
||||||
|
await purgeSentOperations();
|
||||||
|
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user