make possibly conflicting optimistic cache updates write to each other (#1772)

* make possibly conflicting optimistic cache updates write to each other

* always update optimistic caches with cache.modifying items
This commit is contained in:
Keyan 2024-12-27 14:52:32 -06:00 committed by GitHub
parent 18445b1dc1
commit eb22fdab41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 32 additions and 16 deletions

View File

@ -17,7 +17,8 @@ export default function BookmarkDropdownItem ({ item: { id, meBookmark } }) {
id: `Item:${id}`,
fields: {
meBookmark: () => bookmarkItem.meBookmark
}
},
optimistic: true
})
}
}

View File

@ -18,7 +18,8 @@ export default function CommentEdit ({ comment, editThreshold, onSuccess, onCanc
text () {
return result.text
}
}
},
optimistic: true
})
}
},

View File

@ -30,7 +30,8 @@ export default function Delete ({ itemId, children, onDelete, type = 'post' }) {
url: () => deleteItem.url,
pollCost: () => deleteItem.pollCost,
deletedAt: () => deleteItem.deletedAt
}
},
optimistic: true
})
}
}

View File

@ -84,7 +84,8 @@ export function OutlawDropdownItem ({ item }) {
id: `Item:${item.id}`,
fields: {
outlawed: () => true
}
},
optimistic: true
})
}
}

View File

@ -209,7 +209,8 @@ function modifyActCache (cache, { result, invoice }) {
}
return existingBoost
}
}
},
optimistic: true
})
}
@ -228,7 +229,8 @@ function updateAncestors (cache, { result, invoice }) {
commentSats (existingCommentSats = 0) {
return existingCommentSats + sats
}
}
},
optimistic: true
})
})
}

View File

@ -22,7 +22,8 @@ export const payBountyCacheMods = {
bountyPaidTo (existingPaidTo = []) {
return [...(existingPaidTo || []), Number(id)]
}
}
},
optimistic: true
})
},
onPayError: (e, cache, { data }) => {
@ -36,7 +37,8 @@ export const payBountyCacheMods = {
bountyPaidTo (existingPaidTo = []) {
return (existingPaidTo || []).filter(i => i !== Number(id))
}
}
},
optimistic: true
})
}
}

View File

@ -123,7 +123,8 @@ export function usePollVote ({ query = POLL_VOTE, itemId }) {
poll.count += 1
return poll
}
}
},
optimistic: true
})
cache.modify({
id: `PollOption:${id}`,
@ -131,7 +132,8 @@ export function usePollVote ({ query = POLL_VOTE, itemId }) {
count (existingCount) {
return existingCount + 1
}
}
},
optimistic: true
})
}
@ -154,7 +156,8 @@ export function usePollVote ({ query = POLL_VOTE, itemId }) {
poll.count -= 1
return poll
}
}
},
optimistic: true
})
cache.modify({
id: `PollOption:${id}`,
@ -162,7 +165,8 @@ export function usePollVote ({ query = POLL_VOTE, itemId }) {
count (existingCount) {
return existingCount - 1
}
}
},
optimistic: true
})
}

View File

@ -78,7 +78,8 @@ export default forwardRef(function Reply ({
})
return [newCommentRef, ...existingCommentRefs]
}
}
},
optimistic: true
})
// no lag for itemRepetition
@ -102,7 +103,8 @@ export default forwardRef(function Reply ({
ncomments (existingNComments = 0) {
return existingNComments + 1
}
}
},
optimistic: true
})
})

View File

@ -17,7 +17,8 @@ export default function SubscribeDropdownItem ({ item: { id, meSubscription } })
id: `Item:${id}`,
fields: {
meSubscription: () => subscribeItem.meSubscription
}
},
optimistic: true
})
}
}

View File

@ -118,7 +118,8 @@ export function useRetryCreateItem ({ id }) {
`,
data: { bolt11: response.invoice.bolt11 }
})
}
},
optimistic: true
})
paidActionCacheMods?.update?.(cache, { data })
}