mirror of
https://github.com/discourse/discourse.git
synced 2025-02-17 01:22:44 +08:00
FIX: Avoid publishing a gigantic payload.
* Certain sites have way too many categories.
This commit is contained in:
parent
996ce8c443
commit
ed851dbfff
|
@ -95,6 +95,10 @@ export default {
|
||||||
|
|
||||||
bus.subscribe("/client_settings", data => Ember.set(siteSettings, data.name, data.value));
|
bus.subscribe("/client_settings", data => Ember.set(siteSettings, data.name, data.value));
|
||||||
|
|
||||||
|
bus.subscribe("/refresh_client", data => {
|
||||||
|
Discourse.set("assetVersion", data);
|
||||||
|
});
|
||||||
|
|
||||||
if (!Ember.testing) {
|
if (!Ember.testing) {
|
||||||
if (!site.mobileView) {
|
if (!site.mobileView) {
|
||||||
bus.subscribe(alertChannel(user), data => onNotification(data, user));
|
bus.subscribe(alertChannel(user), data => onNotification(data, user));
|
||||||
|
|
|
@ -414,12 +414,18 @@ class Group < ActiveRecord::Base
|
||||||
users.pluck(:username).join(",")
|
users.pluck(:username).join(",")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
PUBLISH_CATEGORIES_LIMIT = 10
|
||||||
|
|
||||||
def add(user)
|
def add(user)
|
||||||
self.users.push(user) unless self.users.include?(user)
|
self.users.push(user) unless self.users.include?(user)
|
||||||
|
|
||||||
MessageBus.publish('/categories', {
|
if self.categories.count < PUBLISH_CATEGORIES_LIMIT
|
||||||
categories: ActiveModel::ArraySerializer.new(self.categories).as_json
|
MessageBus.publish('/categories', {
|
||||||
}, user_ids: [user.id])
|
categories: ActiveModel::ArraySerializer.new(self.categories).as_json
|
||||||
|
}, user_ids: [user.id])
|
||||||
|
else
|
||||||
|
Discourse.request_refresh!(user_ids: [user.id])
|
||||||
|
end
|
||||||
|
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
|
@ -296,12 +296,16 @@ module Discourse
|
||||||
last_read_only[$redis.namespace] = nil
|
last_read_only[$redis.namespace] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.request_refresh!
|
def self.request_refresh!(user_ids: nil)
|
||||||
# Causes refresh on next click for all clients
|
# Causes refresh on next click for all clients
|
||||||
#
|
#
|
||||||
# This is better than `MessageBus.publish "/file-change", ["refresh"]` because
|
# This is better than `MessageBus.publish "/file-change", ["refresh"]` because
|
||||||
# it spreads the refreshes out over a time period
|
# it spreads the refreshes out over a time period
|
||||||
MessageBus.publish '/global/asset-version', 'clobber'
|
if user_ids
|
||||||
|
MessageBus.publish("/refresh_client", 'clobber', user_ids: user_id)
|
||||||
|
else
|
||||||
|
MessageBus.publish('/global/asset-version', 'clobber')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.git_version
|
def self.git_version
|
||||||
|
|
|
@ -539,6 +539,20 @@ describe Group do
|
||||||
expect(message.data[:categories].first[:id]).to eq(category.id)
|
expect(message.data[:categories].first[:id]).to eq(category.id)
|
||||||
expect(message.user_ids).to eq([user.id])
|
expect(message.user_ids).to eq([user.id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "when group belongs to more than #{Group::PUBLISH_CATEGORIES_LIMIT} categories" do
|
||||||
|
it "should publish a message to refresh the user's client" do
|
||||||
|
(Group::PUBLISH_CATEGORIES_LIMIT + 1).times do
|
||||||
|
group.categories << Fabricate(:category)
|
||||||
|
end
|
||||||
|
|
||||||
|
message = MessageBus.track_publish { group.add(user) }.first
|
||||||
|
|
||||||
|
expect(message.data).to eq('clobber')
|
||||||
|
expect(message.channel).to eq('/refresh_client')
|
||||||
|
expect(message.user_ids).to eq([user.id])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user