Skip to content

Commit

Permalink
delete unrelated ids from pinboard table
Browse files Browse the repository at this point in the history
  • Loading branch information
this-pama committed Dec 17, 2024
1 parent 7b67af9 commit 1327064
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions controllers/blog/api/get_articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ exports.get_articles = async (req, res) => {
ON a.pinboard = b.id
WHERE b.id = $1
AND a.db = 5
${page && limit ? `LIMIT $2 OFFSET $3` : ""}
${limit ? `LIMIT $2 OFFSET $3` : ""}
`,
page && limit ? [pinboard, pageLimit, offset] : [pinboard]
limit ? [pinboard, pageLimit, offset] : [pinboard]
);

idList = idList.map((row) => row.pad);
Expand Down Expand Up @@ -112,6 +112,22 @@ exports.get_articles = async (req, res) => {
};
});

// HACK: DELETE FROM PINBOARD TABLE IDS THAT DOES NOT EXIST IN BLOG DB
if (pinboard && idList && idList.length > articleIds.length) {
const unrelatedIds = idList.filter((item) => !articleIds.includes(item));
if (unrelatedIds.length) {
await DB.general.any(
`
DELETE FROM pinboard_contributions a
WHERE a.pinboard = $1
AND a.pad = ANY ($2::int[])
AND a.db = 5
`,
[pinboard, unrelatedIds]
);
}
}

return res.status(200).json(mergedResults);
} catch (err) {
console.error("Database query failed:", err);
Expand Down

0 comments on commit 1327064

Please sign in to comment.