A platform for community discussion. Free, open, simple.
Revert "DEV: Reduce unnecessary UI updates when posts change (#33864)" (#33917)
Sérgio Saquetim7062666af17b
diff --git a/app/assets/javascripts/discourse/app/models/post-stream.js b/app/assets/javascripts/discourse/app/models/post-stream.jsindex 7532d8a99b9..e6e1febad15 100644--- a/app/assets/javascripts/discourse/app/models/post-stream.js+++ b/app/assets/javascripts/discourse/app/models/post-stream.js@@ -843,42 +843,27 @@ export default class PostStream extends RestModel {return Promise.resolve();}- /**- * Updates a post in the stream when it has been changed on the server.- *- * @param {number} postId - The ID of the post to update- * @param {string} updatedAt - The timestamp when the post was last updated- * @param {Object} opts - Additional options for updating the post- * @param {boolean} [opts.preserveCooked] - Whether to preserve the cooked HTML content- * @returns {Promise} A promise that resolves when the post has been updated- */- async triggerChangedPost(postId, updatedAt, opts = {}) {- opts ||= {};+ triggerChangedPost(postId, updatedAt, opts) {+ opts = opts || {};+ const resolved = Promise.resolve();if (!postId) {- return;+ return resolved;}const existing = this._identityMap[postId];-- // Only fetch and update if the post exists and has a different updated timestampif (existing && existing.updated_at !== updatedAt) {- // Fetch the latest post data from the server- const updatedData = await ajax(`/posts/${postId}`);-- // Preserve the existing cooked HTML content if requested- if (opts.preserveCooked) {- updatedData.cooked = existing.cooked;- }-- // Create a new post record with updated data and store it in the identity map.- // Creating a new record will update the existing one in the map, which will then- // trigger re-rendering of UI components that use the tracked data that was updated.- const updatedPost = this.store.createRecord("post", updatedData);+ const url = "/posts/" + postId;+ const store = this.store;+ return ajax(url).then((p) => {+ if (opts.preserveCooked) {+ p.cooked = existing.get("cooked");+ }- // Update the post in the post stream's identity map- this.storePost(updatedPost);+ this.storePost(store.createRecord("post", p));+ });}+ return resolved;}triggerLikedPost(postId, likesCount, userID, eventType) {@@ -1113,9 +1098,7 @@ export default class PostStream extends RestModel {return existing;}- if (post.topic !== this.topic) {- post.topic = this.topic;- }+ post.set("topic", this.topic);this._identityMap[post.get("id")] = post;}return post;diff --git a/app/assets/javascripts/discourse/app/services/store.js b/app/assets/javascripts/discourse/app/services/store.jsindex 1997261c41c..bc7544a8410 100644--- a/app/assets/javascripts/discourse/app/services/store.js+++ b/app/assets/javascripts/discourse/app/services/store.js@@ -418,15 +418,7 @@ export default class StoreService extends Service {klass = RestModel;}- const updatedProperties = klass.munge(obj);- // update only the properties that the value changed to prevent unnecessary rerenders in Glimmer- updatedProperties &&- Object.keys(updatedProperties).forEach((key) => {- if (existing[key] !== updatedProperties[key]) {- existing.set(key, updatedProperties[key]);- }- });-+ existing.setProperties(klass.munge(obj));obj[adapter.primaryKey] = id;return existing;}