mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
FEATURE: automatically update site to latest version of assets
if a user neglects to move around the site it will prompt to do so 2 hours in
This commit is contained in:
parent
abe814412e
commit
a247389d4e
|
@ -130,6 +130,11 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
|||
}
|
||||
},
|
||||
|
||||
requiresRefresh: function(){
|
||||
var desired = Discourse.get("desiredAssetVersion");
|
||||
return desired && Discourse.get("currentAssetVersion") !== desired;
|
||||
}.property("currentAssetVersion", "desiredAssetVersion"),
|
||||
|
||||
assetVersion: function(prop, val) {
|
||||
if(val) {
|
||||
if(this.get("currentAssetVersion")){
|
||||
|
|
|
@ -6,6 +6,17 @@ Discourse.addInitializer(function() {
|
|||
Discourse.MessageBus.start();
|
||||
Discourse.MessageBus.subscribe("/global/asset-version", function(version){
|
||||
Discourse.set("assetVersion",version);
|
||||
|
||||
if(Discourse.get("requiresRefresh")) {
|
||||
// since we can do this transparently for people browsing the forum
|
||||
// hold back the message a couple of hours
|
||||
setTimeout(function() {
|
||||
bootbox.confirm(I18n.lookup("assets_changed_confirm"), function(){
|
||||
document.location.reload();
|
||||
});
|
||||
}, 1000 * 60 * 120);
|
||||
}
|
||||
|
||||
});
|
||||
Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus);
|
||||
}, true);
|
||||
|
|
|
@ -48,13 +48,9 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||
**/
|
||||
routeTo: function(path) {
|
||||
|
||||
// If somehow our asset version changed, force a full reload of desired path
|
||||
var desired = Discourse.get("desiredAssetVersion");
|
||||
if(desired) {
|
||||
if(Discourse.get("currentAssetVersion") !== desired){
|
||||
document.location.href = path;
|
||||
return;
|
||||
}
|
||||
if(Discourse.get("requiresRefresh")){
|
||||
document.location.href = path;
|
||||
return;
|
||||
}
|
||||
|
||||
var oldPath = window.location.pathname;
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
Discourse.SiteSettings = PreloadStore.get('siteSettings');
|
||||
Discourse.Router.map(function() { Discourse.routeBuilder.call(this); });
|
||||
Discourse.start()
|
||||
Discourse.set('assetVersion','<%= Rails.application.assets.digest %>');
|
||||
Discourse.set('assetVersion','<%= Discourse.assets_digest %>');
|
||||
</script>
|
||||
|
||||
<%= javascript_include_tag 'browser-update.js' %>
|
||||
|
|
|
@ -37,11 +37,3 @@ end
|
|||
|
||||
MessageBus.cache_assets = !Rails.env.development?
|
||||
MessageBus.enable_diagnostics
|
||||
|
||||
digest = Rails.application.assets.digest.to_s
|
||||
channel = "/global/asset-version"
|
||||
message = MessageBus.last_message(channel)
|
||||
|
||||
unless message && message.data == digest
|
||||
MessageBus.publish channel, digest
|
||||
end
|
||||
|
|
|
@ -387,6 +387,7 @@ en:
|
|||
|
||||
loading: "Loading..."
|
||||
close: "Close"
|
||||
assets_changed_confirm: "Discourse has been updated, would you like to refresh to get the latest version?"
|
||||
learn_more: "learn more..."
|
||||
|
||||
year: 'year'
|
||||
|
|
|
@ -59,6 +59,20 @@ module Discourse
|
|||
@plugins
|
||||
end
|
||||
|
||||
def self.assets_digest
|
||||
@assets_digest ||= begin
|
||||
digest = Digest::MD5.hexdigest(ActionView::Base.assets_manifest.assets.values.sort.join)
|
||||
|
||||
channel = "/global/asset-version"
|
||||
message = MessageBus.last_message(channel)
|
||||
|
||||
unless message && message.data == digest
|
||||
MessageBus.publish channel, digest
|
||||
end
|
||||
digest
|
||||
end
|
||||
end
|
||||
|
||||
def self.authenticators
|
||||
# TODO: perhaps we don't need auth providers and authenticators maybe one object is enough
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user