-
Notifications
You must be signed in to change notification settings - Fork 2
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
chore: Update npm dependencies and add normalize-url package #109
Conversation
Uplevel your code reviews with CodeRabbit ProCodeRabbit ProIf 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files selected (7)
- web/app/routes/reader.$encodedUrl/components/ContentWithTranslations.tsx (1)
- web/app/routes/reader.$encodedUrl/components/Translation.tsx (1)
- web/app/routes/reader.$encodedUrl/functions/queries.server.ts (1)
- web/app/routes/reader.$encodedUrl/route.tsx (3)
- web/app/routes/translate/route.tsx (3)
- web/app/utils/normalize-and-sanitize-url.server.ts (1)
- web/package.json (1)
Review comments generated (14)
- Review: 4
- LGTM: 10
Tips
Chat with CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files selected (3)
- web/app/routes/reader.$encodedUrl/route.tsx (3)
- web/app/utils/normalize-and-sanitize-url.server.ts (1)
- web/scripts/normalize-page-urls.ts (1)
Review comments generated (13)
- Review: 6
- LGTM: 7
Tips
Chat with CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
export function normalizeAndSanitizeUrl(inputUrl: string): string { | ||
let decodedUrl: string; | ||
try { | ||
decodedUrl = decodeURIComponent(inputUrl); | ||
} catch { | ||
decodedUrl = inputUrl; | ||
} | ||
|
||
return normalizeUrl(decodedUrl, { | ||
stripHash: true, | ||
removeQueryParameters: true, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
web/scripts/normalize-page-urls.ts
Outdated
for (const page of pages) { | ||
const normalizedUrl = normalizeAndSanitizeUrl(page.url); | ||
if (normalizedUrl !== page.url) { | ||
await prisma.page.update({ | ||
where: { id: page.id }, | ||
data: { url: normalizedUrl }, | ||
}); | ||
console.log(`Updated Page URL: ${page.url} -> ${normalizedUrl}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for
ループ内でのデータベース更新は、パフォーマンスに影響を与える可能性があります。バッチ処理を使用して一度に複数のレコードを更新することを検討してください。
- for (const page of pages) {
- const normalizedUrl = normalizeAndSanitizeUrl(page.url);
- if (normalizedUrl !== page.url) {
- await prisma.page.update({
- where: { id: page.id },
- data: { url: normalizedUrl },
- });
- console.log(`Updated Page URL: ${page.url} -> ${normalizedUrl}`);
- }
- }
+ const updatePromises = pages.map(async (page) => {
+ const normalizedUrl = normalizeAndSanitizeUrl(page.url);
+ if (normalizedUrl !== page.url) {
+ await prisma.page.update({
+ where: { id: page.id },
+ data: { url: normalizedUrl },
+ });
+ console.log(`Updated Page URL: ${page.url} -> ${normalizedUrl}`);
+ }
+ });
+ await Promise.all(updatePromises);
web/scripts/normalize-page-urls.ts
Outdated
for (const pageVersion of pageVersions) { | ||
const normalizedUrl = normalizeAndSanitizeUrl(pageVersion.url); | ||
if (normalizedUrl !== pageVersion.url) { | ||
await prisma.pageVersion.update({ | ||
where: { id: pageVersion.id }, | ||
data: { url: normalizedUrl }, | ||
}); | ||
console.log(`Updated PageVersion URL: ${pageVersion.url} -> ${normalizedUrl}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同様に、for
ループ内でのデータベース更新はバッチ処理を使用して最適化できます。
- for (const pageVersion of pageVersions) {
- const normalizedUrl = normalizeAndSanitizeUrl(pageVersion.url);
- if (normalizedUrl !== pageVersion.url) {
- await prisma.pageVersion.update({
- where: { id: pageVersion.id },
- data: { url: normalizedUrl },
- });
- console.log(`Updated PageVersion URL: ${pageVersion.url} -> ${normalizedUrl}`);
- }
- }
+ const updatePromises = pageVersions.map(async (pageVersion) => {
+ const normalizedUrl = normalizeAndSanitizeUrl(pageVersion.url);
+ if (normalizedUrl !== pageVersion.url) {
+ await prisma.pageVersion.update({
+ where: { id: pageVersion.id },
+ data: { url: normalizedUrl },
+ });
+ console.log(`Updated PageVersion URL: ${pageVersion.url} -> ${normalizedUrl}`);
+ }
+ });
+ await Promise.all(updatePromises);
web/scripts/normalize-page-urls.ts
Outdated
} catch (error) { | ||
console.error("Error during URL normalization:", error); | ||
} finally { | ||
await prisma.$disconnect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} finally { | ||
await prisma.$disconnect(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…into ttizze/bug-issue-97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files selected (2)
- web/package.json (2)
- web/scripts/normalize-page-urls.ts (1)
Review comments generated (9)
- Review: 2
- LGTM: 7
Tips
Chat with CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
try { | ||
// Normalize Page URLs | ||
while (true) { | ||
const pages = await prisma.page.findMany({ | ||
take: batchSize, | ||
skip: processedPageCount, | ||
select: { id: true, url: true }, | ||
}); | ||
|
||
if (pages.length === 0) break; | ||
|
||
for (const page of pages) { | ||
const normalizedUrl = normalizeAndSanitizeUrl(page.url); | ||
if (normalizedUrl !== page.url) { | ||
await prisma.page.update({ | ||
where: { id: page.id }, | ||
data: { url: normalizedUrl }, | ||
}); | ||
console.log(`Updated Page URL: ${page.url} -> ${normalizedUrl}`); | ||
} | ||
} | ||
|
||
processedPageCount += pages.length; | ||
console.log(`Processed ${processedPageCount} pages`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この部分のコードは、ページURLを正規化およびサニタイズするためにバッチ処理を行っていますが、データベース操作のパフォーマンスを向上させるためにトランザクションを使用することを検討してください。これにより、複数の更新操作を一括でコミットでき、パフォーマンスが向上します。
await prisma.$transaction(async (prisma) => {
while (true) {
const pages = await prisma.page.findMany({
take: batchSize,
skip: processedPageCount,
select: { id: true, url: true },
});
if (pages.length === 0) break;
for (const page of pages) {
const normalizedUrl = normalizeAndSanitizeUrl(page.url);
if (normalizedUrl !== page.url) {
await prisma.page.update({
where: { id: page.id },
data: { url: normalizedUrl },
});
console.log(`Updated Page URL: ${page.url} -> ${normalizedUrl}`);
}
}
processedPageCount += pages.length;
console.log(`Processed ${processedPageCount} pages`);
}
});
// Normalize PageVersion URLs | ||
while (true) { | ||
const pageVersions = await prisma.pageVersion.findMany({ | ||
take: batchSize, | ||
skip: processedPageVersionCount, | ||
select: { id: true, url: true }, | ||
}); | ||
|
||
if (pageVersions.length === 0) break; | ||
|
||
for (const pageVersion of pageVersions) { | ||
const normalizedUrl = normalizeAndSanitizeUrl(pageVersion.url); | ||
if (normalizedUrl !== pageVersion.url) { | ||
await prisma.pageVersion.update({ | ||
where: { id: pageVersion.id }, | ||
data: { url: normalizedUrl }, | ||
}); | ||
console.log( | ||
`Updated PageVersion URL: ${pageVersion.url} -> ${normalizedUrl}`, | ||
); | ||
} | ||
} | ||
|
||
processedPageVersionCount += pageVersions.length; | ||
console.log(`Processed ${processedPageVersionCount} page versions`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この部分のコードも同様に、ページバージョンURLを正規化およびサニタイズするためにバッチ処理を行っていますが、データベース操作のパフォーマンスを向上させるためにトランザクションを使用することを検討してください。
await prisma.$transaction(async (prisma) => {
while (true) {
const pageVersions = await prisma.pageVersion.findMany({
take: batchSize,
skip: processedPageVersionCount,
select: { id: true, url: true },
});
if (pageVersions.length === 0) break;
for (const pageVersion of pageVersions) {
const normalizedUrl = normalizeAndSanitizeUrl(pageVersion.url);
if (normalizedUrl !== pageVersion.url) {
await prisma.pageVersion.update({
where: { id: pageVersion.id },
data: { url: normalizedUrl },
});
console.log(
`Updated PageVersion URL: ${pageVersion.url} -> ${normalizedUrl}`,
);
}
}
processedPageVersionCount += pageVersions.length;
console.log(`Processed ${processedPageVersionCount} page versions`);
}
});
Summary by CodeRabbit