Skip to content

Commit

Permalink
Merge pull request #336 from SaekiTominaga/crawler-resource-hash
Browse files Browse the repository at this point in the history
「ウェブ巡回(リソース)」の差分比較をコンテンツの長さ→ハッシュ値に変更
  • Loading branch information
SaekiTominaga authored Jul 8, 2023
2 parents d1f0b6e + d1b3c20 commit 5c27aad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
16 changes: 6 additions & 10 deletions html/admin/crawler-resource.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@
<th scope="col">優先</th>
<th scope="col">🌐</th>
<th scope="col">セレクター</th>
<th scope="col">サイズ</th>
<th scope="col">更新日時</th>
<th scope="col">ハッシュ値</th>
<th scope="col">エラー</th>
</tr>
</thead>
<tbody>
Expand All @@ -145,15 +145,11 @@
<a href="<%= resourcePage.url %>" referrerpolicy="no-referrer"><%= resourcePage.title %></a>
<p style="margin-block-start: 0.5em; font-size: 80%"><%= resourcePage.url %></p>
</td>
<td><%= resourcePage.priority %></td>
<td><%_ if (resourcePage.browser) { _%><%_ } _%></td>
<td class="u-cell -center"><%= resourcePage.priority %></td>
<td class="u-cell -center"><%_ if (resourcePage.browser) { _%><%_ } _%></td>
<td class="u-cell -wrap-anywhere"><%= resourcePage.selector %></td>
<td><%= resourcePage.content_length %></td>
<%_ if (resourcePage.last_modified !== null) { _%>
<td><%= resourcePage.last_modified.format('YYYY年M月D日 H時m分') %></td>
<%_ } else { _%>
<td></td>
<%_ } _%>
<td><%= resourcePage.content_hash %></td>
<td class="u-cell -center"><%_ if (resourcePage.error) { _%><strong style="color: red"></strong><%_ } _%></td>
</tr>
<%_ } _%>
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/node/@types/view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ declare namespace CrawlerResourceView {
priority: string;
browser: boolean;
selector: string | null;
content_length: number;
last_modified: import('dayjs').Dayjs | null;
content_hash: string;
error: boolean;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export default class CrawlerResourceController extends Controller implements Con
priority: resoursePage.priority,
browser: resoursePage.browser,
selector: resoursePage.selector,
content_length: resoursePage.content_length,
last_modified: resoursePage.last_modified,
content_hash: resoursePage.content_hash,
error: resoursePage.error,
});

resourcePageListView.set(categoryName, resourcePageOfCategoryView);
Expand Down
21 changes: 10 additions & 11 deletions packages/backend/node/src/dao/CrawlerResourceDao.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dayjs, { Dayjs } from 'dayjs';
import CrawlerDao from './CrawlerDao.js';
import DbUtil from '../util/DbUtil.js';

Expand All @@ -9,8 +8,8 @@ interface ResourcePage {
priority: string;
browser: boolean;
selector: string | null;
content_length: number;
last_modified: Dayjs | null;
content_hash: string;
error: boolean;
}

interface ReviseData {
Expand Down Expand Up @@ -42,14 +41,14 @@ export default class CrawlerResourceDao extends CrawlerDao {
p.name AS priority,
r.browser AS browser,
r.selector AS selector,
r.content_length AS content_length,
r.last_modified AS last_modified
r.content_hash AS content_hash,
r.error AS error
FROM
d_resource r,
m_class c,
m_priority p
WHERE
r.class = c.fk AND
r.category = c.fk AND
r.priority = p.fk
ORDER BY
c.sort,
Expand All @@ -68,8 +67,8 @@ export default class CrawlerResourceDao extends CrawlerDao {
priority: row.priority,
browser: Boolean(row.browser),
selector: row.selector,
content_length: row.content_length,
last_modified: row.last_modified !== null ? dayjs.unix(row.last_modified) : null,
content_hash: row.content_hash,
error: Boolean(row.error),
});
}

Expand All @@ -94,7 +93,7 @@ export default class CrawlerResourceDao extends CrawlerDao {
const sth = await dbh.prepare(`
INSERT INTO
d_resource
(url, title, class, priority, browser, selector)
(url, title, category, priority, browser, selector)
VALUES
(:url, :title, :category, :priority, :browser, :selector)
`);
Expand Down Expand Up @@ -135,7 +134,7 @@ export default class CrawlerResourceDao extends CrawlerDao {
d_resource
SET
title = :title,
class = :category,
category = :category,
priority = :priority,
browser = :browser,
selector = :selector
Expand Down Expand Up @@ -200,7 +199,7 @@ export default class CrawlerResourceDao extends CrawlerDao {
const sth = await dbh.prepare(`
SELECT
title,
class AS category,
category,
priority,
browser,
selector
Expand Down

0 comments on commit 5c27aad

Please sign in to comment.