Skip to content

Commit

Permalink
chore: better observability for geodata import
Browse files Browse the repository at this point in the history
  • Loading branch information
zackpollard committed Nov 5, 2024
1 parent 5edbb93 commit c189b41
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/src/repositories/map.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export class MapRepository implements IMapRepository {
const input = createReadStream(filePath);
let bufferGeodata: QueryDeepPartialEntity<GeodataPlacesEntity>[] = [];
const lineReader = readLine.createInterface({ input });
let count = 0;

for await (const line of lineReader) {
const lineSplit = line.split('\t');
Expand All @@ -257,8 +258,12 @@ export class MapRepository implements IMapRepository {
}
const geoData = lineToEntityMapper(lineSplit);
bufferGeodata.push(geoData);
if (bufferGeodata.length > 1000) {
if (bufferGeodata.length >= 1000) {
await queryRunner.manager.upsert(GeodataPlacesEntity, bufferGeodata, ['id']);
count += bufferGeodata.length;
if (count % 10_000 === 0) {
this.logger.log(`${count} geodata records imported`);
}
bufferGeodata = [];
}
}
Expand Down

0 comments on commit c189b41

Please sign in to comment.