mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:03:22 +08: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() {
|
||||
var result = Em.A();
|
||||
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;
|
||||
result.pushObject(Discourse.SiteSetting.create(s));
|
||||
});
|
||||
result.set('diags', settings.diags);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
Handles routes related to viewing and editing site settings.
|
||||
|
||||
@class AdminSiteSettingsRoute
|
||||
@class AdminSiteSettingsRoute
|
||||
@extends Discourse.Route
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
|
@ -13,5 +13,5 @@ Discourse.AdminSiteSettingsRoute = Discourse.Route.extend({
|
|||
|
||||
renderTemplate: function() {
|
||||
this.render('admin/templates/site_settings', {into: 'admin/templates/admin'});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,3 +12,6 @@
|
|||
</div>
|
||||
|
||||
{{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
|
||||
|
||||
def index
|
||||
@site_settings = SiteSetting.all_settings
|
||||
render_json_dump(@site_settings.as_json)
|
||||
site_settings = SiteSetting.all_settings
|
||||
info = {site_settings: site_settings, diags: SiteSetting.diags }
|
||||
render_json_dump(info.as_json)
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
|
@ -299,7 +299,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
unless seen?(date) || has_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
|
||||
|
||||
|
@ -493,7 +493,7 @@ class User < ActiveRecord::Base
|
|||
.where(['id in (
|
||||
SELECT topic_id FROM posts p
|
||||
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
|
||||
p.user_id = ?
|
||||
)', self.id])
|
||||
|
|
|
@ -5,4 +5,17 @@ class UserVisit < ActiveRecord::Base
|
|||
def self.by_day(sinceDaysAgo=30)
|
||||
where("visited_at >= ?", sinceDaysAgo.days.ago).group(:visited_at).order(:visited_at).count
|
||||
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
|
||||
|
|
|
@ -3,6 +3,7 @@ module Jobs
|
|||
class EnsureDbConsistency < Jobs::Base
|
||||
def execute(args)
|
||||
TopicUser.ensure_consistency!
|
||||
UserVisit.ensure_consistency!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -115,6 +115,7 @@ module SiteSettingExtension
|
|||
message = msg.data
|
||||
if message["process"] != pid
|
||||
begin
|
||||
@last_message_processed = msg.global_id
|
||||
# picks a db
|
||||
MessageBus.on_connect.call(msg.site_id)
|
||||
SiteSetting.refresh!
|
||||
|
@ -127,6 +128,12 @@ module SiteSettingExtension
|
|||
end
|
||||
end
|
||||
|
||||
def diags
|
||||
{
|
||||
last_message_processed: @last_message_processed
|
||||
}
|
||||
end
|
||||
|
||||
def process_id
|
||||
@@process_id ||= SecureRandom.uuid
|
||||
end
|
||||
|
@ -162,7 +169,7 @@ module SiteSettingExtension
|
|||
SiteSetting.create!(name: name, value: val, data_type: type)
|
||||
end
|
||||
|
||||
MessageBus.publish('/site_settings', {process: process_id})
|
||||
@last_message_sent = MessageBus.publish('/site_settings', {process: process_id})
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,20 @@
|
|||
require 'spec_helper'
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user