Skip to content

Commit

Permalink
- Fixed faulty tag loop detection (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
funmaker committed Jan 20, 2024
1 parent a1ec24d commit 3898034
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Added `host` config option (https://github.com/funmaker/Hybooru/issues/38)
- Added support for PORT and HOST envvar override
- Removed DOCKERIZED envvar, Dockerfile now uses PORT (https://github.com/funmaker/Hybooru/issues/36)
- Fixed faulty tag loop detection (https://github.com/funmaker/Hybooru/issues/39)


# v1.9.0
Expand Down
16 changes: 8 additions & 8 deletions server/helpers/dbImport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,16 @@ async function normalizeTagRelations(postgres: PoolClient) {
FROM paths
INNER JOIN tag_siblings ON tag_siblings.tagid = paths.tagid
WHERE paths.tagid != ALL(paths.visited)
), loops(tagid, visited) AS (
SELECT *
), loops(tagid, path) AS (
SELECT tagid, visited || tagid
FROM paths
WHERE tagid = visited[1] AND tagid <= ALL(visited)
ORDER BY tagid
)
DELETE FROM tag_siblings
USING loops
WHERE tag_siblings.tagid = loops.tagid AND tag_siblings.betterid = loops.visited[array_upper(loops.visited, 1)]
RETURNING loops.visited || loops.tagid AS path
WHERE tag_siblings.tagid = loops.tagid AND tag_siblings.betterid = loops.path[2]
RETURNING path
`);

printProgress([1, 6], "Normalizing tags");
Expand Down Expand Up @@ -376,16 +376,16 @@ async function normalizeTagRelations(postgres: PoolClient) {
FROM paths
INNER JOIN tag_parents ON tag_parents.tagid = paths.tagid
WHERE paths.tagid != ALL(paths.visited)
), loops(tagid, visited) AS (
SELECT *
), loops(tagid, path) AS (
SELECT tagid, visited || tagid
FROM paths
WHERE tagid = visited[1] AND tagid <= ALL(visited)
ORDER BY tagid
)
DELETE FROM tag_parents
USING loops
WHERE tag_parents.tagid = loops.tagid AND tag_parents.parentid = loops.visited[array_upper(loops.visited, 1)]
RETURNING loops.visited || loops.tagid AS path
WHERE tag_parents.tagid = loops.tagid AND tag_parents.parentid = loops.path[2]
RETURNING path
`);

printProgress([6, 6], "Normalizing tags");
Expand Down

0 comments on commit 3898034

Please sign in to comment.