Skip to content
Snippets Groups Projects
Commit 7bcf2449 authored by ArtOfCode-'s avatar ArtOfCode-
Browse files

0.8.0

parents 5ef877bb a5c5ff22
Branches
Tags v0.8.0
No related merge requests found
...@@ -11,7 +11,7 @@ gem 'mysql2', '~> 0.5.4' ...@@ -11,7 +11,7 @@ gem 'mysql2', '~> 0.5.4'
gem 'puma', '~> 5.6' gem 'puma', '~> 5.6'
gem 'rails', '~> 7.0.0' gem 'rails', '~> 7.0.0'
gem 'rails-html-sanitizer', '~> 1.4' gem 'rails-html-sanitizer', '~> 1.4'
gem 'redis', '~> 5.0' gem 'redis', '~> 4.8'
gem 'rotp', '~> 6.2' gem 'rotp', '~> 6.2'
gem 'sass-rails', '~> 6.0' gem 'sass-rails', '~> 6.0'
gem 'sprockets', '~> 4.1' gem 'sprockets', '~> 4.1'
......
...@@ -107,7 +107,6 @@ GEM ...@@ -107,7 +107,6 @@ GEM
coffee-script-source (1.12.2) coffee-script-source (1.12.2)
commonmarker (0.23.5) commonmarker (0.23.5)
concurrent-ruby (1.1.10) concurrent-ruby (1.1.10)
connection_pool (2.2.5)
counter_culture (3.2.1) counter_culture (3.2.1)
activerecord (>= 4.2) activerecord (>= 4.2)
activesupport (>= 4.2) activesupport (>= 4.2)
...@@ -262,10 +261,7 @@ GEM ...@@ -262,10 +261,7 @@ GEM
rb-fsevent (0.11.2) rb-fsevent (0.11.2)
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
redis (5.0.4) redis (4.8.0)
redis-client (>= 0.7.4)
redis-client (0.8.0)
connection_pool
regexp_parser (2.5.0) regexp_parser (2.5.0)
responders (3.0.1) responders (3.0.1)
actionpack (>= 5.0) actionpack (>= 5.0)
...@@ -396,7 +392,7 @@ DEPENDENCIES ...@@ -396,7 +392,7 @@ DEPENDENCIES
rails (~> 7.0.0) rails (~> 7.0.0)
rails-controller-testing (~> 1.0) rails-controller-testing (~> 1.0)
rails-html-sanitizer (~> 1.4) rails-html-sanitizer (~> 1.4)
redis (~> 5.0) redis (~> 4.8)
reverse_markdown (~> 2.1) reverse_markdown (~> 2.1)
rmagick rmagick
rotp (~> 6.2) rotp (~> 6.2)
......
...@@ -268,7 +268,9 @@ class ApplicationController < ActionController::Base ...@@ -268,7 +268,9 @@ class ApplicationController < ActionController::Base
@hot_questions = Rails.cache.fetch('hot_questions', expires_in: 4.hours) do @hot_questions = Rails.cache.fetch('hot_questions', expires_in: 4.hours) do
Rack::MiniProfiler.step 'hot_questions: cache miss' do Rack::MiniProfiler.step 'hot_questions: cache miss' do
Post.undeleted.where(last_activity: (Rails.env.development? ? 365 : 7).days.ago..DateTime.now) Post.undeleted.where(closed: false)
.where(locked: false)
.where(last_activity: (Rails.env.development? ? 365 : 7).days.ago..DateTime.now)
.where(post_type_id: [Question.post_type_id, Article.post_type_id]) .where(post_type_id: [Question.post_type_id, Article.post_type_id])
.joins(:category).where(categories: { use_for_hot_posts: true }) .joins(:category).where(categories: { use_for_hot_posts: true })
.where('score >= ?', SiteSetting['HotPostsScoreThreshold']) .where('score >= ?', SiteSetting['HotPostsScoreThreshold'])
......
...@@ -99,6 +99,7 @@ class PostsController < ApplicationController ...@@ -99,6 +99,7 @@ class PostsController < ApplicationController
end end
if @post.save if @post.save
@post.update(last_activity: @post.created_at, last_activity_by: current_user)
if @post_type.has_parent? if @post_type.has_parent?
unless @post.user_id == @post.parent.user_id unless @post.user_id == @post.parent.user_id
@post.parent.user.create_notification("New response to your post #{@post.parent.title}", @post.parent.user.create_notification("New response to your post #{@post.parent.title}",
......
...@@ -265,9 +265,9 @@ class Post < ApplicationRecord ...@@ -265,9 +265,9 @@ class Post < ApplicationRecord
def maximum_tags def maximum_tags
if tags_cache.length > 5 if tags_cache.length > 5
errors.add(:tags, "can't have more than 5 tags") errors.add(:base, "Post can't have more than 5 tags.")
elsif tags_cache.empty? elsif tags_cache.empty?
errors.add(:tags, 'must have at least one tag') errors.add(:base, 'Post must have at least one tag.')
end end
end end
......
class PostFlagType < ApplicationRecord class PostFlagType < ApplicationRecord
include CommunityRelated include CommunityRelated
belongs_to :post_type, optional: true
validates :name, uniqueness: { scope: [:community_id], case_sensitive: false } validates :name, uniqueness: { scope: [:community_id], case_sensitive: false }
scope :not_confidential, -> { where(confidential: false) } scope :not_confidential, -> { where(confidential: false) }
......
...@@ -24,7 +24,10 @@ Rails.application.configure do ...@@ -24,7 +24,10 @@ Rails.application.configure do
redis_config = YAML.safe_load(processed, permitted_classes: [], permitted_symbols: [], aliases: true)["redis_#{Rails.env}"] redis_config = YAML.safe_load(processed, permitted_classes: [], permitted_symbols: [], aliases: true)["redis_#{Rails.env}"]
config.cache_store = QPixel::NamespacedEnvCache.new( config.cache_store = QPixel::NamespacedEnvCache.new(
ActiveSupport::Cache::RedisCacheStore.new( ActiveSupport::Cache::RedisCacheStore.new(
url: "redis://#{redis_config['host']}:#{redis_config['port']}" **redis_config.deep_symbolize_keys.merge(reconnect_attempts: 3),
error_handler: -> (method:, returning:, exception:) {
Rails.logger.error("Cache error: method=#{method} returning=#{returning} exception=#{exception.message}")
}
) )
) )
......
...@@ -58,9 +58,16 @@ Rails.application.configure do ...@@ -58,9 +58,16 @@ Rails.application.configure do
# Prepend all log lines with the following tags. # Prepend all log lines with the following tags.
config.log_tags = [ :subdomain, :uuid ] config.log_tags = [ :subdomain, :uuid ]
# Use a different cache store in production. # Set the cache store to the redis that was configured in the database.yml
processed = ERB.new(File.read(Rails.root.join('config', 'database.yml'))).result(binding)
redis_config = YAML.safe_load(processed, permitted_classes: [], permitted_symbols: [], aliases: true)["redis_#{Rails.env}"]
config.cache_store = QPixel::NamespacedEnvCache.new( config.cache_store = QPixel::NamespacedEnvCache.new(
ActiveSupport::Cache::RedisCacheStore.new(url: 'redis://localhost:6379/1') ActiveSupport::Cache::RedisCacheStore.new(
**redis_config.deep_symbolize_keys.merge(reconnect_attempts: 3),
error_handler: -> (method:, returning:, exception:) {
Rails.logger.error("Cache error: method=#{method} returning=#{returning} exception=#{exception.message}")
}
)
) )
# Use a real queuing backend for Active Job (and separate queues per environment). # Use a real queuing backend for Active Job (and separate queues per environment).
......
...@@ -28,11 +28,15 @@ Rails.application.configure do ...@@ -28,11 +28,15 @@ Rails.application.configure do
config.consider_all_requests_local = true config.consider_all_requests_local = true
config.action_controller.perform_caching = false config.action_controller.perform_caching = false
# Set the cache store to the redis that was configured in the database.yml
processed = ERB.new(File.read(Rails.root.join('config', 'database.yml'))).result(binding) processed = ERB.new(File.read(Rails.root.join('config', 'database.yml'))).result(binding)
redis_config = YAML.safe_load(processed, permitted_classes: [], permitted_symbols: [], aliases: true)["redis_#{Rails.env}"] redis_config = YAML.safe_load(processed, permitted_classes: [], permitted_symbols: [], aliases: true)["redis_#{Rails.env}"]
config.cache_store = QPixel::NamespacedEnvCache.new( config.cache_store = QPixel::NamespacedEnvCache.new(
ActiveSupport::Cache::RedisCacheStore.new( ActiveSupport::Cache::RedisCacheStore.new(
url: "redis://#{redis_config['host']}:#{redis_config['port']}" **redis_config.deep_symbolize_keys.merge(reconnect_attempts: 3),
error_handler: -> (method:, returning:, exception:) {
Rails.logger.error("Cache error: method=#{method} returning=#{returning} exception=#{exception.message}")
}
) )
) )
......
...@@ -63,6 +63,26 @@ sorted.each do |f, type| ...@@ -63,6 +63,26 @@ sorted.each do |f, type|
# otherwise, no need to worry, just create it # otherwise, no need to worry, just create it
[seed] [seed]
end end
# Transform all _id relations into the actual rails objects to pass validations
seeds = seeds.map do |seed|
columns = type.column_names.select { |name| name.match(/^.*_id$/) }
new_seed = seed.deep_symbolize_keys
columns.each do |column|
begin
column_type_name = column.chomp('_id')
column_type = column_type_name.classify.constantize
new_seed = new_seed.except(column.to_sym)
.merge(column_type_name.to_sym => column_type.unscoped.find(seed[column.to_sym]))
rescue StandardError
# Either the type does not exist or the value specified as the id is not valid, ignore.
next
end
end
new_seed
end
# Actually create the objects and count successes
objs = type.create seeds objs = type.create seeds
skipped += objs.select { |o| o.errors.any? }.size skipped += objs.select { |o| o.errors.any? }.size
created += objs.select { |o| !o.errors.any? }.size created += objs.select { |o| !o.errors.any? }.size
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
tag_set_id: <%= TagSet.unscoped.where(name: 'Main').first.id %> tag_set_id: <%= TagSet.unscoped.where(name: 'Main').first.id %>
use_for_hot_posts: true use_for_hot_posts: true
use_for_advertisement: true use_for_advertisement: true
license_id: <%= License.unscoped.first.id %>
- name: Meta - name: Meta
short_wiki: Discussions and feedback about the site itself in Q&A format. short_wiki: Discussions and feedback about the site itself in Q&A format.
...@@ -21,3 +22,4 @@ ...@@ -21,3 +22,4 @@
use_for_hot_posts: true use_for_hot_posts: true
use_for_advertisement: false use_for_advertisement: false
color_code: bluegray color_code: bluegray
license_id: <%= License.unscoped.first.id %>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment