mirror of
https://github.com/wassname/talk.git
synced 2026-07-07 05:36:31 +08:00
[CORL-1240] Check existing data before handling subscriptions (#3077)
* fix: check existing data before handling subscriptions * fix: typo Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -24,11 +24,16 @@ function handleCommentEnteredModerationQueue(
|
||||
return;
|
||||
}
|
||||
const comment = rootField.getLinkedRecord("comment")!;
|
||||
const commentID = comment.getValue("id")!;
|
||||
const edgeID = `edge-${commentID}`;
|
||||
const edgeInQueue = Boolean(store.get(edgeID));
|
||||
if (edgeInQueue) {
|
||||
// Comment edge already in the queue, ignore it as it might be just expected race condition,
|
||||
// unless the server is sending the same response multiple times.
|
||||
return;
|
||||
}
|
||||
comment.setValue(true, "enteredLive");
|
||||
const commentsEdge = store.create(
|
||||
`edge-${comment.getValue("id")!}`,
|
||||
"CommentsEdge"
|
||||
);
|
||||
const commentsEdge = store.create(edgeID, "CommentsEdge");
|
||||
commentsEdge.setValue(comment.getValue("createdAt"), "cursor");
|
||||
commentsEdge.setLinkedRecord(comment, "node");
|
||||
const connection = getQueueConnection(store, queue, storyID, siteID, section);
|
||||
|
||||
@@ -23,14 +23,12 @@ function handleCommentLeftModerationQueue(
|
||||
if (!rootField) {
|
||||
return;
|
||||
}
|
||||
const comment = rootField.getLinkedRecord("comment")!;
|
||||
const commentID = rootField
|
||||
.getLinkedRecord("comment")!
|
||||
.getValue("id")! as string;
|
||||
const commentInStore = store.get(commentID);
|
||||
if (commentInStore) {
|
||||
// Mark that the status of the comment was live updated.
|
||||
commentInStore.setValue(true, "statusLiveUpdated");
|
||||
}
|
||||
// Mark that the status of the comment was live updated.
|
||||
comment.setValue(true, "statusLiveUpdated");
|
||||
const connection = getQueueConnection(store, queue, storyID, siteID, section);
|
||||
if (connection) {
|
||||
const linked = connection.getLinkedRecords("viewNewEdges") || [];
|
||||
|
||||
@@ -30,14 +30,12 @@ const SingleModerateSubscription = createSubscription(
|
||||
`,
|
||||
variables,
|
||||
updater: (store) => {
|
||||
const commentID = store
|
||||
const comment = store
|
||||
.getRootField("commentStatusUpdated")!
|
||||
.getLinkedRecord("comment")!
|
||||
.getValue("id")! as string;
|
||||
const commentInStore = store.get(commentID);
|
||||
if (commentInStore) {
|
||||
.getLinkedRecord("comment")!;
|
||||
if (comment) {
|
||||
// Mark that the status of the comment was live updated.
|
||||
commentInStore.setValue(true, "statusLiveUpdated");
|
||||
comment.setValue(true, "statusLiveUpdated");
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -58,6 +58,17 @@ const CommentReplyCreatedSubscription = createSubscription(
|
||||
return;
|
||||
}
|
||||
const comment = rootField.getLinkedRecord("comment")!;
|
||||
const commentInStore = Boolean(
|
||||
// We use store from environment here, because it does not contain the response data yet!
|
||||
environment
|
||||
.getStore()
|
||||
.getSource()
|
||||
.get(comment.getValue("id") as string)
|
||||
);
|
||||
if (commentInStore) {
|
||||
return;
|
||||
}
|
||||
|
||||
comment.setValue(true, "enteredLive");
|
||||
|
||||
const parentID = comment
|
||||
|
||||
+18
@@ -72,6 +72,24 @@ const CommentCreatedSubscription = createSubscription(
|
||||
`,
|
||||
variables,
|
||||
updater: (store) => {
|
||||
const rootField = store.getRootField("commentCreated");
|
||||
if (!rootField) {
|
||||
return;
|
||||
}
|
||||
const commentID = rootField
|
||||
.getLinkedRecord("comment")!
|
||||
.getValue("id")! as string;
|
||||
|
||||
const commentInStore = Boolean(
|
||||
// We use store from environment here, because it does not contain the response data yet!
|
||||
environment.getStore().getSource().get(commentID)
|
||||
);
|
||||
if (commentInStore) {
|
||||
// Comment already in the queue, ignore it as it might be just expected race condition,
|
||||
// unless the server is sending the same response multiple times.
|
||||
return;
|
||||
}
|
||||
|
||||
if (variables.orderBy === GQLCOMMENT_SORT.CREATED_AT_DESC) {
|
||||
updateForNewestFirst(store, variables.storyID);
|
||||
return;
|
||||
|
||||
+17
@@ -72,6 +72,23 @@ const CommentReleasedSubscription = createSubscription(
|
||||
`,
|
||||
variables,
|
||||
updater: (store) => {
|
||||
const rootField = store.getRootField("commentReleased");
|
||||
if (!rootField) {
|
||||
return;
|
||||
}
|
||||
const commentID = rootField
|
||||
.getLinkedRecord("comment")!
|
||||
.getValue("id")! as string;
|
||||
const commentInStore = Boolean(
|
||||
// We use store from environment here, because it does not contain the response data yet!
|
||||
environment.getStore().getSource().get(commentID)
|
||||
);
|
||||
if (commentInStore) {
|
||||
// Comment already in the queue, ignore it as it might be just expected race condition,
|
||||
// unless the server is sending the same response multiple times.
|
||||
return;
|
||||
}
|
||||
|
||||
if (variables.orderBy === GQLCOMMENT_SORT.CREATED_AT_DESC) {
|
||||
updateForNewestFirst(store, variables.storyID);
|
||||
return;
|
||||
|
||||
+17
@@ -75,6 +75,23 @@ const UnansweredCommentCreatedSubscription = createSubscription(
|
||||
`,
|
||||
variables,
|
||||
updater: (store) => {
|
||||
const rootField = store.getRootField("commentCreated");
|
||||
if (!rootField) {
|
||||
return;
|
||||
}
|
||||
const commentID = rootField
|
||||
.getLinkedRecord("comment")!
|
||||
.getValue("id")! as string;
|
||||
const commentInStore = Boolean(
|
||||
// We use store from environment here, because it does not contain the response data yet!
|
||||
environment.getStore().getSource().get(commentID)
|
||||
);
|
||||
if (commentInStore) {
|
||||
// Comment already in the queue, ignore it as it might be just expected race condition,
|
||||
// unless the server is sending the same response multiple times.
|
||||
return;
|
||||
}
|
||||
|
||||
if (variables.orderBy === GQLCOMMENT_SORT.CREATED_AT_DESC) {
|
||||
updateForNewestFirst(store, variables.storyID);
|
||||
return;
|
||||
|
||||
+17
@@ -75,6 +75,23 @@ const UnansweredCommentReleasedSubscription = createSubscription(
|
||||
`,
|
||||
variables,
|
||||
updater: (store) => {
|
||||
const rootField = store.getRootField("commentReleased");
|
||||
if (!rootField) {
|
||||
return;
|
||||
}
|
||||
const commentID = rootField
|
||||
.getLinkedRecord("comment")!
|
||||
.getValue("id")! as string;
|
||||
const commentInStore = Boolean(
|
||||
// We use store from environment here, because it does not contain the response data yet!
|
||||
environment.getStore().getSource().get(commentID)
|
||||
);
|
||||
if (commentInStore) {
|
||||
// Comment already in the queue, ignore it as it might be just expected race condition,
|
||||
// unless the server is sending the same response multiple times.
|
||||
return;
|
||||
}
|
||||
|
||||
if (variables.orderBy === GQLCOMMENT_SORT.CREATED_AT_DESC) {
|
||||
updateForNewestFirst(store, variables.storyID);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user