mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #3476 from omnivore-app/fix/update-db-job
fix: update-label job uses too much cpu
This commit is contained in:
commit
cf27174c70
2 changed files with 26 additions and 18 deletions
|
|
@ -17,16 +17,15 @@ export const updateLabels = async (data: UpdateLabelsData) => {
|
|||
return authTrx(
|
||||
async (tx) =>
|
||||
tx.query(
|
||||
`WITH labels_agg AS (
|
||||
SELECT array_agg(DISTINCT l.name) AS names_agg
|
||||
FROM omnivore.labels l
|
||||
INNER JOIN omnivore.entity_labels el ON el.label_id = l.id
|
||||
LEFT JOIN omnivore.highlight h ON h.id = el.highlight_id
|
||||
WHERE el.library_item_id = $1 OR h.library_item_id = $1
|
||||
)
|
||||
UPDATE omnivore.library_item li
|
||||
SET label_names = COALESCE((SELECT names_agg FROM labels_agg), ARRAY[]::TEXT[])
|
||||
WHERE li.id = $1`,
|
||||
`UPDATE omnivore.library_item
|
||||
SET label_names = COALESCE((
|
||||
SELECT array_agg(DISTINCT l.name)
|
||||
FROM omnivore.labels l
|
||||
INNER JOIN omnivore.entity_labels el
|
||||
ON el.label_id = l.id
|
||||
AND el.library_item_id = $1
|
||||
), ARRAY[]::TEXT[])
|
||||
WHERE id = $1`,
|
||||
[data.libraryItemId]
|
||||
),
|
||||
undefined,
|
||||
|
|
@ -38,14 +37,13 @@ export const updateHighlight = async (data: UpdateHighlightData) => {
|
|||
return authTrx(
|
||||
async (tx) =>
|
||||
tx.query(
|
||||
`WITH highlight_agg AS (
|
||||
SELECT array_agg(COALESCE(annotation, '')) AS annotation_agg
|
||||
FROM omnivore.highlight
|
||||
WHERE library_item_id = $1
|
||||
)
|
||||
UPDATE omnivore.library_item
|
||||
SET highlight_annotations = COALESCE((SELECT annotation_agg FROM highlight_agg), ARRAY[]::TEXT[])
|
||||
WHERE id = $1`,
|
||||
`UPDATE omnivore.library_item
|
||||
SET highlight_annotations = COALESCE((
|
||||
SELECT array_agg(COALESCE(annotation, ''))
|
||||
FROM omnivore.highlight
|
||||
WHERE library_item_id = $1
|
||||
), ARRAY[]::TEXT[])
|
||||
WHERE id = $1`,
|
||||
[data.libraryItemId]
|
||||
),
|
||||
undefined,
|
||||
|
|
|
|||
|
|
@ -679,7 +679,12 @@ export const bulkEnqueueUpdateLabels = async (data: UpdateLabelsData[]) => {
|
|||
name: UPDATE_LABELS_JOB,
|
||||
data: d,
|
||||
opts: {
|
||||
attempts: 3,
|
||||
priority: 1,
|
||||
backoff: {
|
||||
type: 'exponential',
|
||||
delay: 1000,
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
|
|
@ -699,7 +704,12 @@ export const enqueueUpdateHighlight = async (data: UpdateHighlightData) => {
|
|||
|
||||
try {
|
||||
return queue.add(UPDATE_HIGHLIGHT_JOB, data, {
|
||||
attempts: 3,
|
||||
priority: 1,
|
||||
backoff: {
|
||||
type: 'exponential',
|
||||
delay: 1000,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('error enqueuing update highlight job', error)
|
||||
|
|
|
|||
Loading…
Reference in a new issue