Skip to content

Commit

Permalink
Merge branch 'develop' of digital.github.com:digital-go-jp/abr-geocod…
Browse files Browse the repository at this point in the history
…er into develop
  • Loading branch information
wf9a5m75 committed Oct 30, 2024
2 parents c164224 + 9d93819 commit 0daf23f
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"execa-cjs": "^9.1.1",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"rimraf": "^6.0.1",
"ts-add-js-extension": "^1.6.4",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
Expand All @@ -77,7 +78,6 @@
"node-gyp": "^10.2.0",
"proj4": "^2.12.1",
"range-parser": "^1.2.1",
"rimraf": "^6.0.1",
"string-hash": "^1.1.3",
"unzipper": "^0.11.6",
"winston": "^3.14.2",
Expand Down
32 changes: 32 additions & 0 deletions src/domain/services/remove-files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import path from 'node:path';
import fs from 'node:fs';
import { RegExpEx } from "@domain/services/reg-exp-ex";

export const removeFiles = async (params: Required<{
dir: string;

Check failure on line 6 in src/domain/services/remove-files.ts

View workflow job for this annotation

GitHub Actions / lint_and_build

Expected indentation of 2 spaces but found 4
filename: string | RegExp;

Check failure on line 7 in src/domain/services/remove-files.ts

View workflow job for this annotation

GitHub Actions / lint_and_build

Expected indentation of 2 spaces but found 4
}>) => {
const filePattern: RegExp = (() => {

Check failure on line 9 in src/domain/services/remove-files.ts

View workflow job for this annotation

GitHub Actions / lint_and_build

Expected indentation of 2 spaces but found 4
if (typeof params.filename === 'string') {

Check failure on line 10 in src/domain/services/remove-files.ts

View workflow job for this annotation

GitHub Actions / lint_and_build

Expected indentation of 4 spaces but found 8
return RegExpEx.create(`^${params.filename}$`);

Check failure on line 11 in src/domain/services/remove-files.ts

View workflow job for this annotation

GitHub Actions / lint_and_build

Expected indentation of 6 spaces but found 12
} else {

Check failure on line 12 in src/domain/services/remove-files.ts

View workflow job for this annotation

GitHub Actions / lint_and_build

Expected indentation of 4 spaces but found 8
return params.filename;

Check failure on line 13 in src/domain/services/remove-files.ts

View workflow job for this annotation

GitHub Actions / lint_and_build

Expected indentation of 6 spaces but found 12
}

Check failure on line 14 in src/domain/services/remove-files.ts

View workflow job for this annotation

GitHub Actions / lint_and_build

Expected indentation of 4 spaces but found 8
})();

Check failure on line 15 in src/domain/services/remove-files.ts

View workflow job for this annotation

GitHub Actions / lint_and_build

Expected indentation of 2 spaces but found 4

// 古いキャッシュファイルを削除

Check failure on line 17 in src/domain/services/remove-files.ts

View workflow job for this annotation

GitHub Actions / lint_and_build

Expected indentation of 2 spaces but found 4
const dir = await fs.promises.opendir(params.dir);
const removedFiles: string[] = [];
for await (const dirent of dir) {
if (!filePattern.test(dirent.name)) {
continue;
}
removedFiles.push(dirent.name);
try {
await fs.promises.unlink(path.join(dirent.parentPath, dirent.name));
} catch (e: unknown) {

Check warning on line 27 in src/domain/services/remove-files.ts

View workflow job for this annotation

GitHub Actions / lint_and_build

'e' is defined but never used. Allowed unused caught errors must match /^_/u
// Do nothing here
}
}
return removedFiles;
};
7 changes: 3 additions & 4 deletions src/interface/cli/commands/geocode-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ const geocodeCommand: CommandModule = {

// 合計のリクエスト数をセット
if (progressBar) {
progressBar.update(0, {
message: 'geocoding...',
});
progressBar?.setTotal(total);
}

Expand Down Expand Up @@ -284,7 +281,9 @@ const geocodeCommand: CommandModule = {
const streamCounter = new StreamCounter({
fps: 10,
callback(current) {
progressBar?.update(current);
progressBar?.update(current, {
message: 'geocoding...',
});
},
});
await streamPromises.pipeline(
Expand Down
2 changes: 1 addition & 1 deletion src/usecases/download/download-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class Downloader {

// ダウンロード処理を行う
// 最大6コネクション
const numOfDownloadThreads = Math.max(Math.floor(parallel / 3 * 1), 1);
const numOfDownloadThreads = Math.min(Math.max(Math.floor(parallel / 3 * 2), 1), 6);
const downloadTransform = new DownloadTransform({
container: this.container,
maxConcurrency: numOfDownloadThreads,
Expand Down
7 changes: 5 additions & 2 deletions src/usecases/geocode/models/city-and-ward-trie-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { kan2num } from '../services/kan2num';
import { toHiragana } from '../services/to-hiragana';
import { AbrGeocoderDiContainer } from './abr-geocoder-di-container';
import { TrieAddressFinder } from "./trie/trie-finder";
import { rimraf } from "rimraf";
import { removeFiles } from "@domain/services/remove-files";

export class CityAndWardTrieFinder extends TrieAddressFinder<CityMatchingInfo> {

Expand Down Expand Up @@ -51,7 +51,10 @@ export class CityAndWardTrieFinder extends TrieAddressFinder<CityMatchingInfo> {
}

// 古いキャッシュファイルを削除
await rimraf(`${path.join(cacheDir, 'city-and-ward_*.v8')}`);
await removeFiles({
dir: cacheDir,
filename: 'city-and-ward_.*\.v8'
});

// キャッシュがなければ、Databaseからデータをロードして読み込む
// キャッシュファイルも作成する
Expand Down
7 changes: 5 additions & 2 deletions src/usecases/geocode/models/county-and-city-trie-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { kan2num } from '../services/kan2num';
import { toHiragana } from '../services/to-hiragana';
import { AbrGeocoderDiContainer } from './abr-geocoder-di-container';
import { TrieAddressFinder } from "./trie/trie-finder";
import { rimraf } from "rimraf";
import { removeFiles } from "@domain/services/remove-files";

export class CountyAndCityTrieFinder extends TrieAddressFinder<CityMatchingInfo> {

Expand Down Expand Up @@ -50,7 +50,10 @@ export class CountyAndCityTrieFinder extends TrieAddressFinder<CityMatchingInfo>
}

// 古いキャッシュファイルを削除
await rimraf(`${path.join(diContainer.cacheDir, 'county-and-city_*.v8')}`);
await removeFiles({
dir: diContainer.cacheDir,
filename: 'county-and-city_.*\.v8'
});

// キャッシュがなければ、Databaseからデータをロードして読み込む
// キャッシュファイルも作成する
Expand Down
7 changes: 5 additions & 2 deletions src/usecases/geocode/models/kyoto-street-trie-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { toHiragana } from '../services/to-hiragana';
import { AbrGeocoderDiContainer } from './abr-geocoder-di-container';
import { TrieAddressFinder } from "./trie/trie-finder";
import { MatchLevel } from "@domain/types/geocode/match-level";
import { rimraf } from "rimraf";
import { removeFiles } from "@domain/services/remove-files";

export class KyotoStreetTrieFinder extends TrieAddressFinder<KoazaMachingInfo> {

Expand Down Expand Up @@ -73,7 +73,10 @@ export class KyotoStreetTrieFinder extends TrieAddressFinder<KoazaMachingInfo> {
}

// 古いキャッシュファイルを削除
await rimraf(`${path.join(diContainer.cacheDir, 'kyoto-street_*.v8')}`);
await removeFiles({
dir: diContainer.cacheDir,
filename: 'kyoto-street_.*\.v8'
});

// キャッシュがなければ、Databaseからデータをロードして読み込む
// キャッシュファイルも作成する
Expand Down
7 changes: 5 additions & 2 deletions src/usecases/geocode/models/oaza-cho-trie-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { RegExpEx } from "@domain/services/reg-exp-ex";
import { OazaChoMachingInfo } from "@domain/types/geocode/oaza-cho-info";
import fs from 'node:fs';
import path from 'node:path';
import { rimraf } from "rimraf";
import { jisKanji } from '../services/jis-kanji';
import { kan2num } from '../services/kan2num';
import { toHankakuAlphaNum } from "../services/to-hankaku-alpha-num";
import { toHiragana } from '../services/to-hiragana';
import { AbrGeocoderDiContainer } from './abr-geocoder-di-container';
import { CharNode } from "./trie/char-node";
import { TrieAddressFinder } from "./trie/trie-finder";
import { removeFiles } from "@domain/services/remove-files";

export class OazaChoTrieFinder extends TrieAddressFinder<OazaChoMachingInfo> {

Expand Down Expand Up @@ -107,7 +107,10 @@ export class OazaChoTrieFinder extends TrieAddressFinder<OazaChoMachingInfo> {
// ここではエラーを殺すだけで良い
}
// 古いキャッシュファイルを削除
await rimraf(`${path.join(diContainer.cacheDir, 'oaza-cho_*.v8')}`);
await removeFiles({
dir: diContainer.cacheDir,
filename: 'oaza-cho_.*\.v8'
});

// キャッシュがなければ、Databaseからデータをロードして読み込む
// キャッシュファイルも作成する
Expand Down
7 changes: 5 additions & 2 deletions src/usecases/geocode/models/pref-trie-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { kan2num } from '../services/kan2num';
import { toHiragana } from '../services/to-hiragana';
import { AbrGeocoderDiContainer } from './abr-geocoder-di-container';
import { TrieAddressFinder } from "./trie/trie-finder";
import { rimraf } from "rimraf";
import { removeFiles } from "@domain/services/remove-files";

export class PrefTrieFinder extends TrieAddressFinder<PrefInfo> {

Expand Down Expand Up @@ -50,7 +50,10 @@ export class PrefTrieFinder extends TrieAddressFinder<PrefInfo> {
}

// 古いキャッシュファイルを削除
await rimraf(`${path.join(diContainer.cacheDir, 'pref_*.v8')}`);
await removeFiles({
dir: diContainer.cacheDir,
filename: 'pref_.*\.v8'
});

// キャッシュがなければ、Databaseからデータをロードして読み込む
// キャッシュファイルも作成する
Expand Down
7 changes: 5 additions & 2 deletions src/usecases/geocode/models/tokyo23-town-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { kan2num } from '../services/kan2num';
import { toHiragana } from '../services/to-hiragana';
import { AbrGeocoderDiContainer } from './abr-geocoder-di-container';
import { TrieAddressFinder } from "./trie/trie-finder";
import { rimraf } from "rimraf";
import { removeFiles } from "@domain/services/remove-files";

export class Tokyo23TownTrieFinder extends TrieAddressFinder<TownMatchingInfo> {

Expand Down Expand Up @@ -55,7 +55,10 @@ export class Tokyo23TownTrieFinder extends TrieAddressFinder<TownMatchingInfo> {
}

// 古いキャッシュファイルを削除
await rimraf(`${path.join(diContainer.cacheDir, 'tokyo23-town_*.v8')}`);
await removeFiles({
dir: diContainer.cacheDir,
filename: 'tokyo23-town_.*\.v8'
});

// キャッシュがなければ、Databaseからデータをロードして読み込む
// キャッシュファイルも作成する
Expand Down
7 changes: 5 additions & 2 deletions src/usecases/geocode/models/tokyo23-ward-trie-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { kan2num } from '../services/kan2num';
import { toHiragana } from '../services/to-hiragana';
import { AbrGeocoderDiContainer } from './abr-geocoder-di-container';
import { TrieAddressFinder } from "./trie/trie-finder";
import { rimraf } from "rimraf";
import { removeFiles } from "@domain/services/remove-files";

export class Tokyo23WardTrieFinder extends TrieAddressFinder<CityMatchingInfo> {

Expand Down Expand Up @@ -55,7 +55,10 @@ export class Tokyo23WardTrieFinder extends TrieAddressFinder<CityMatchingInfo> {
}

// 古いキャッシュファイルを削除
await rimraf(`${path.join(diContainer.cacheDir, 'tokyo23-ward_*.v8')}`);
await removeFiles({
dir: diContainer.cacheDir,
filename: 'tokyo23-ward_.*\.v8'
});

// キャッシュがなければ、Databaseからデータをロードして読み込む
// キャッシュファイルも作成する
Expand Down
7 changes: 5 additions & 2 deletions src/usecases/geocode/models/ward-and-oaza-trie-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { kan2num } from '../services/kan2num';
import { toHiragana } from '../services/to-hiragana';
import { AbrGeocoderDiContainer } from './abr-geocoder-di-container';
import { TrieAddressFinder } from "./trie/trie-finder";
import { rimraf } from "rimraf";
import { removeFiles } from "@domain/services/remove-files";

export class WardAndOazaTrieFinder extends TrieAddressFinder<WardAndOazaMatchingInfo> {

Expand Down Expand Up @@ -49,7 +49,10 @@ export class WardAndOazaTrieFinder extends TrieAddressFinder<WardAndOazaMatching
}

// 古いキャッシュファイルを削除
await rimraf(`${path.join(diContainer.cacheDir, 'ward-and-oaza_*.v8')}`);
await removeFiles({
dir: diContainer.cacheDir,
filename: 'ward-and-oaza_.*\.v8'
});

// キャッシュがなければ、Databaseからデータをロードして読み込む
// キャッシュファイルも作成する
Expand Down
7 changes: 5 additions & 2 deletions src/usecases/geocode/models/ward-trie-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { toHankakuAlphaNum } from "../services/to-hankaku-alpha-num";
import { toHiragana } from '../services/to-hiragana';
import { AbrGeocoderDiContainer } from './abr-geocoder-di-container';
import { TrieAddressFinder } from "./trie/trie-finder";
import { rimraf } from "rimraf";
import { removeFiles } from "@domain/services/remove-files";

export class WardTrieFinder extends TrieAddressFinder<WardMatchingInfo> {

Expand Down Expand Up @@ -49,7 +49,10 @@ export class WardTrieFinder extends TrieAddressFinder<WardMatchingInfo> {
}

// 古いキャッシュファイルを削除
await rimraf(`${path.join(diContainer.cacheDir, 'ward_*.v8')}`);
await removeFiles({
dir: diContainer.cacheDir,
filename: 'ward_.*\.v8'
});

// キャッシュがなければ、Databaseからデータをロードして読み込む
// キャッシュファイルも作成する
Expand Down

0 comments on commit 0daf23f

Please sign in to comment.