Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

全体的なリファクタリング #152

Merged
merged 4 commits into from
Aug 4, 2024
Merged

Conversation

ttizze
Copy link
Owner

@ttizze ttizze commented Aug 4, 2024

Closes #150

translateにまとめられていたhtml処理を分離
translateから既存の翻訳がある場合はスキップする機能を削除

routeのtranslateとfeatureのtranslateが名前が被っていたのでrouteをtranslatorに修正

Summary by CodeRabbit

## リリースノート

### New Feature
- `extractTranslations` 関数を追加し、JSON解析と正規表現フォールバックロジックを実装
- `splitNumberedElements` 関数を追加し、テキスト長に基づいてチャンクに分割するロジックを実装

### Refactor
- `extractNumberedElements` 関数を `htmlparser2` を使用するようリファクタリング
- 翻訳プロセス全体を管理する新しい関数群を追加
- インポートパスの変更 (`generateSystemMessage`)

### Removed
- `translate` および `processTranslation` 関数を削除
- `getOrCreateSourceTextIdAndPageVersionSourceText` 関数を削除
- `getDbUser` および `getOrCreateAIUser` 関数を削除

### Types
- 新しい型 `NumberedElement` を追加

Copy link

github-actions bot commented Aug 4, 2024

This PR is linked to issue #150

@github-actions github-actions bot mentioned this pull request Aug 4, 2024
Copy link

github-actions bot commented Aug 4, 2024

Image description CodeRabbit

### ウォークスルー
この変更は、HTMLコンテンツの解析に`htmlparser2`を使用するためのリファクタリングと、新しいデータベース操作関数や翻訳処理ロジックの追加を含みます。また、不要な関数やファイルの削除、インポートパスの修正も行われています。

### 変更点
| ファイル | 要約 |
| --- | --- |
| `web/app/feature/translate/functions/mutations.server.ts` | `getOrCreateSourceTextIdAndPageVersionSourceText` 関数が削除されました。 |
| `web/app/feature/translate/libs/translation.ts` | `translate`および`processTranslation`関数を含むファイル全体が削除されました。 |
| `web/app/feature/translate/libs/translationUtils.ts` | `extractNumberedElements`関数を`htmlparser2`を使用するようにリファクタリングしました。 |
| `web/app/features/translate/jobs/translate-job.server.ts` | `extractNumberedElements`関数の呼び出しから`title`引数が削除されました。 |
| `web/app/features/translate/lib/translation.ts` | `extractNumberedElements`関数をリファクタリングし、新しい翻訳プロセス管理関数群を追加しました。 |
| `web/app/features/translate/services/anthropic.ts`, `web/app/features/translate/services/openai.ts` | `generateSystemMessage`のインポートパスが変更されました。 |
| `web/app/features/translate/types.ts` | 新しい型 `NumberedElement` を追加しました。 |
| `web/app/features/translate/utils/extractTranslations.server.ts` | `extractTranslations`関数を追加しました。 |
| `web/app/features/translate/utils/splitNumberedElements.server.ts` | `splitNumberedElements`関数を追加しました。 |
| `web/app/libs/db/user.server.ts` | `getDbUser` 関数と `getOrCreateAIUser` 関数が削除されました。 |

Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

@ttizze ttizze changed the title refactor: Update extractNumberedElements to use htmlparser2 for parsing HTML content 全体的なリファクタリング Aug 4, 2024
Comment on lines 9 to 14
"start": "remix-serve ./build/server/index.js",
"typecheck": "tsc",
"check": "bunx @biomejs/biome check --write .",
"clear-queues": "tsx scripts/clear-queues.ts",
"seed": "NODE_ENV=development prisma db seed"
},
"prisma": {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [4-4]

parseDocument 関数は非同期処理をサポートしていないため、大規模なHTMLコンテンツを扱う場合にパフォーマンスの問題が発生する可能性があります。非同期処理をサポートするライブラリを検討してください。

-import { parseDocument } from 'htmlparser2';
+import { parseDocument, Parser } from 'htmlparser2';

@ttizze ttizze merged commit 8543825 into main Aug 4, 2024
5 checks passed
@ttizze ttizze deleted the ttizze/refactor-issue-150 branch August 4, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

全体リファクタ
1 participant