mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
some minimal site settings diags
fix issue where days_visited was totally out of sync
This commit is contained in:
parent
a7f92ec0c1
commit
a2cca2540e
@ -91,10 +91,11 @@ Discourse.SiteSetting.reopenClass({
|
|||||||
findAll: function() {
|
findAll: function() {
|
||||||
var result = Em.A();
|
var result = Em.A();
|
||||||
Discourse.ajax({url: Discourse.getURL("/admin/site_settings")}).then(function (settings) {
|
Discourse.ajax({url: Discourse.getURL("/admin/site_settings")}).then(function (settings) {
|
||||||
settings.each(function(s) {
|
settings.site_settings.each(function(s) {
|
||||||
s.originalValue = s.value;
|
s.originalValue = s.value;
|
||||||
result.pushObject(Discourse.SiteSetting.create(s));
|
result.pushObject(Discourse.SiteSetting.create(s));
|
||||||
});
|
});
|
||||||
|
result.set('diags', settings.diags);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
Handles routes related to viewing and editing site settings.
|
Handles routes related to viewing and editing site settings.
|
||||||
|
|
||||||
@class AdminSiteSettingsRoute
|
@class AdminSiteSettingsRoute
|
||||||
@extends Discourse.Route
|
@extends Discourse.Route
|
||||||
@namespace Discourse
|
@namespace Discourse
|
||||||
@module Discourse
|
@module Discourse
|
||||||
@ -13,5 +13,5 @@ Discourse.AdminSiteSettingsRoute = Discourse.Route.extend({
|
|||||||
|
|
||||||
renderTemplate: function() {
|
renderTemplate: function() {
|
||||||
this.render('admin/templates/site_settings', {into: 'admin/templates/admin'});
|
this.render('admin/templates/site_settings', {into: 'admin/templates/admin'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -12,3 +12,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{collection contentBinding="filteredContent" classNames="form-horizontal settings" itemViewClass="Discourse.SiteSettingView"}}
|
{{collection contentBinding="filteredContent" classNames="form-horizontal settings" itemViewClass="Discourse.SiteSettingView"}}
|
||||||
|
|
||||||
|
<!-- will remove as soon as I figure out what is going on -->
|
||||||
|
<p><small>Diagnostics: last_message_processed {{content.diags.last_message_processed}}</small></p>
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
class Admin::SiteSettingsController < Admin::AdminController
|
class Admin::SiteSettingsController < Admin::AdminController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@site_settings = SiteSetting.all_settings
|
site_settings = SiteSetting.all_settings
|
||||||
render_json_dump(@site_settings.as_json)
|
info = {site_settings: site_settings, diags: SiteSetting.diags }
|
||||||
|
render_json_dump(info.as_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
@ -299,7 +299,7 @@ class User < ActiveRecord::Base
|
|||||||
|
|
||||||
unless seen?(date) || has_visit_record?(date)
|
unless seen?(date) || has_visit_record?(date)
|
||||||
adding_visit_record(date)
|
adding_visit_record(date)
|
||||||
User.increment_counter(:days_visited, 1)
|
User.update_all('days_visited = days_visited + 1', id: self.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -493,7 +493,7 @@ class User < ActiveRecord::Base
|
|||||||
.where(['id in (
|
.where(['id in (
|
||||||
SELECT topic_id FROM posts p
|
SELECT topic_id FROM posts p
|
||||||
JOIN topics t2 ON t2.id = p.topic_id
|
JOIN topics t2 ON t2.id = p.topic_id
|
||||||
WHERE deleted_at IS NULL AND
|
WHERE p.deleted_at IS NULL AND
|
||||||
t2.user_id <> p.user_id AND
|
t2.user_id <> p.user_id AND
|
||||||
p.user_id = ?
|
p.user_id = ?
|
||||||
)', self.id])
|
)', self.id])
|
||||||
|
@ -5,4 +5,17 @@ class UserVisit < ActiveRecord::Base
|
|||||||
def self.by_day(sinceDaysAgo=30)
|
def self.by_day(sinceDaysAgo=30)
|
||||||
where("visited_at >= ?", sinceDaysAgo.days.ago).group(:visited_at).order(:visited_at).count
|
where("visited_at >= ?", sinceDaysAgo.days.ago).group(:visited_at).order(:visited_at).count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.ensure_consistency!
|
||||||
|
exec_sql <<SQL
|
||||||
|
UPDATE users u set days_visited =
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM user_visits v WHERE v.user_id = u.id
|
||||||
|
)
|
||||||
|
WHERE days_visited <>
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM user_visits v WHERE v.user_id = u.id
|
||||||
|
)
|
||||||
|
SQL
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ module Jobs
|
|||||||
class EnsureDbConsistency < Jobs::Base
|
class EnsureDbConsistency < Jobs::Base
|
||||||
def execute(args)
|
def execute(args)
|
||||||
TopicUser.ensure_consistency!
|
TopicUser.ensure_consistency!
|
||||||
|
UserVisit.ensure_consistency!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -115,6 +115,7 @@ module SiteSettingExtension
|
|||||||
message = msg.data
|
message = msg.data
|
||||||
if message["process"] != pid
|
if message["process"] != pid
|
||||||
begin
|
begin
|
||||||
|
@last_message_processed = msg.global_id
|
||||||
# picks a db
|
# picks a db
|
||||||
MessageBus.on_connect.call(msg.site_id)
|
MessageBus.on_connect.call(msg.site_id)
|
||||||
SiteSetting.refresh!
|
SiteSetting.refresh!
|
||||||
@ -127,6 +128,12 @@ module SiteSettingExtension
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def diags
|
||||||
|
{
|
||||||
|
last_message_processed: @last_message_processed
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def process_id
|
def process_id
|
||||||
@@process_id ||= SecureRandom.uuid
|
@@process_id ||= SecureRandom.uuid
|
||||||
end
|
end
|
||||||
@ -162,7 +169,7 @@ module SiteSettingExtension
|
|||||||
SiteSetting.create!(name: name, value: val, data_type: type)
|
SiteSetting.create!(name: name, value: val, data_type: type)
|
||||||
end
|
end
|
||||||
|
|
||||||
MessageBus.publish('/site_settings', {process: process_id})
|
@last_message_sent = MessageBus.publish('/site_settings', {process: process_id})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,20 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe UserVisit do
|
describe UserVisit do
|
||||||
|
it 'can ensure consistency' do
|
||||||
|
u = Fabricate(:user)
|
||||||
|
u.update_visit_record!(2.weeks.ago.to_date)
|
||||||
|
u.last_seen_at = 2.weeks.ago
|
||||||
|
u.save
|
||||||
|
u.update_visit_record!(1.day.ago.to_date)
|
||||||
|
|
||||||
|
u.reload
|
||||||
|
u.days_visited.should == 2
|
||||||
|
|
||||||
|
u.days_visited = 1
|
||||||
|
UserVisit.ensure_consistency!
|
||||||
|
|
||||||
|
u.reload
|
||||||
|
u.days_visited.should == 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user