add entity sync logs
This commit is contained in:
parent
cfc89be734
commit
b6b6aa84c6
|
@ -14,6 +14,7 @@ import {
|
||||||
EncryptedEntity,
|
EncryptedEntity,
|
||||||
} from 'types/entity';
|
} from 'types/entity';
|
||||||
import { getLatestVersionEntities } from 'utils/entity';
|
import { getLatestVersionEntities } from 'utils/entity';
|
||||||
|
import { addLogLine } from 'utils/logging';
|
||||||
|
|
||||||
const ENDPOINT = getEndpoint();
|
const ENDPOINT = getEndpoint();
|
||||||
|
|
||||||
|
@ -105,10 +106,14 @@ export const syncEntities = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const syncEntity = async <T>(type: EntityType): Promise<Entity<T>> => {
|
const syncEntity = async <T>(type: EntityType): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
let entities = await getLocalEntity(type);
|
let entities = await getLocalEntity<T>(type);
|
||||||
|
addLogLine(
|
||||||
|
`Syncing ${type} entities localEntitiesCount: ${entities.length}`
|
||||||
|
);
|
||||||
let syncTime = await getEntityLastSyncTime(type);
|
let syncTime = await getEntityLastSyncTime(type);
|
||||||
|
addLogLine(`Syncing ${type} entities syncTime: ${syncTime}`);
|
||||||
let response: EntitySyncDiffResponse;
|
let response: EntitySyncDiffResponse;
|
||||||
do {
|
do {
|
||||||
response = await getEntityDiff(type, syncTime);
|
response = await getEntityDiff(type, syncTime);
|
||||||
|
@ -152,6 +157,9 @@ const syncEntity = async <T>(type: EntityType): Promise<Entity<T>> => {
|
||||||
}
|
}
|
||||||
await localForage.setItem(ENTITY_TABLES[type], nonDeletedEntities);
|
await localForage.setItem(ENTITY_TABLES[type], nonDeletedEntities);
|
||||||
await localForage.setItem(ENTITY_SYNC_TIME_TABLES[type], syncTime);
|
await localForage.setItem(ENTITY_SYNC_TIME_TABLES[type], syncTime);
|
||||||
|
addLogLine(
|
||||||
|
`Syncing ${type} entities nonDeletedEntitiesCount: ${nonDeletedEntities.length}`
|
||||||
|
);
|
||||||
} while (response.hasMore);
|
} while (response.hasMore);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError(e, 'Sync entity failed');
|
logError(e, 'Sync entity failed');
|
||||||
|
|
Loading…
Reference in a new issue