mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #1891 from omnivore-app/fix/labels-to-add-event
Only publish labels to add to the pubsub queue
This commit is contained in:
commit
a85bc721c3
2 changed files with 25 additions and 12 deletions
|
|
@ -57,7 +57,8 @@ export const addLabelInPage = async (
|
|||
export const updateLabelsInPage = async (
|
||||
pageId: string,
|
||||
labels: Label[],
|
||||
ctx: PageContext
|
||||
ctx: PageContext,
|
||||
labelsToAdd?: Label[]
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const { body } = await client.update({
|
||||
|
|
@ -74,12 +75,16 @@ export const updateLabelsInPage = async (
|
|||
})
|
||||
|
||||
if (body.result !== 'updated') return false
|
||||
|
||||
for (const label of labels) {
|
||||
await ctx.pubsub.entityCreated<Label & { pageId: string }>(
|
||||
EntityType.LABEL,
|
||||
{ pageId, ...label },
|
||||
ctx.uid
|
||||
if (labelsToAdd) {
|
||||
// publish labels to be added
|
||||
await Promise.all(
|
||||
labelsToAdd.map((label) =>
|
||||
ctx.pubsub.entityCreated<Label & { pageId: string }>(
|
||||
EntityType.LABEL,
|
||||
{ pageId, ...label },
|
||||
ctx.uid
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -243,12 +243,20 @@ export const setLabelsResolver = authorized<
|
|||
errorCodes: [SetLabelsErrorCode.NotFound],
|
||||
}
|
||||
}
|
||||
|
||||
// filter out labels that are already set
|
||||
const labelsToAdd = labels.filter(
|
||||
(label) => !page.labels?.some((pageLabel) => pageLabel.id === label.id)
|
||||
)
|
||||
// update labels in the page
|
||||
const updated = await updateLabelsInPage(pageId, labels, {
|
||||
pubsub,
|
||||
uid,
|
||||
})
|
||||
const updated = await updateLabelsInPage(
|
||||
pageId,
|
||||
labels,
|
||||
{
|
||||
pubsub,
|
||||
uid,
|
||||
},
|
||||
labelsToAdd
|
||||
)
|
||||
if (!updated) {
|
||||
return {
|
||||
errorCodes: [SetLabelsErrorCode.NotFound],
|
||||
|
|
|
|||
Loading…
Reference in a new issue