Skip to content

Commit

Permalink
0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtOfCode- committed Sep 23, 2022
2 parents 5ef877b + a5c5ff2 commit 7bcf244
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gem 'mysql2', '~> 0.5.4'
gem 'puma', '~> 5.6'
gem 'rails', '~> 7.0.0'
gem 'rails-html-sanitizer', '~> 1.4'
gem 'redis', '~> 5.0'
gem 'redis', '~> 4.8'
gem 'rotp', '~> 6.2'
gem 'sass-rails', '~> 6.0'
gem 'sprockets', '~> 4.1'
Expand Down
8 changes: 2 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ GEM
coffee-script-source (1.12.2)
commonmarker (0.23.5)
concurrent-ruby (1.1.10)
connection_pool (2.2.5)
counter_culture (3.2.1)
activerecord (>= 4.2)
activesupport (>= 4.2)
Expand Down Expand Up @@ -262,10 +261,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (5.0.4)
redis-client (>= 0.7.4)
redis-client (0.8.0)
connection_pool
redis (4.8.0)
regexp_parser (2.5.0)
responders (3.0.1)
actionpack (>= 5.0)
Expand Down Expand Up @@ -396,7 +392,7 @@ DEPENDENCIES
rails (~> 7.0.0)
rails-controller-testing (~> 1.0)
rails-html-sanitizer (~> 1.4)
redis (~> 5.0)
redis (~> 4.8)
reverse_markdown (~> 2.1)
rmagick
rotp (~> 6.2)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ def pull_pinned_links_and_hot_questions

@hot_questions = Rails.cache.fetch('hot_questions', expires_in: 4.hours) 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])
.joins(:category).where(categories: { use_for_hot_posts: true })
.where('score >= ?', SiteSetting['HotPostsScoreThreshold'])
Expand Down
1 change: 1 addition & 0 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def create
end

if @post.save
@post.update(last_activity: @post.created_at, last_activity_by: current_user)
if @post_type.has_parent?
unless @post.user_id == @post.parent.user_id
@post.parent.user.create_notification("New response to your post #{@post.parent.title}",
Expand Down
4 changes: 2 additions & 2 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ def license_valid

def maximum_tags
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?
errors.add(:tags, 'must have at least one tag')
errors.add(:base, 'Post must have at least one tag.')
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/post_flag_type.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class PostFlagType < ApplicationRecord
include CommunityRelated

belongs_to :post_type, optional: true

validates :name, uniqueness: { scope: [:community_id], case_sensitive: false }

scope :not_confidential, -> { where(confidential: false) }
Expand Down
5 changes: 4 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
redis_config = YAML.safe_load(processed, permitted_classes: [], permitted_symbols: [], aliases: true)["redis_#{Rails.env}"]
config.cache_store = QPixel::NamespacedEnvCache.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}")
}
)
)

Expand Down
11 changes: 9 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@
# Prepend all log lines with the following tags.
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(
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).
Expand Down
6 changes: 5 additions & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
config.consider_all_requests_local = true
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)
redis_config = YAML.safe_load(processed, permitted_classes: [], permitted_symbols: [], aliases: true)["redis_#{Rails.env}"]
config.cache_store = QPixel::NamespacedEnvCache.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}")
}
)
)

Expand Down
22 changes: 21 additions & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,27 @@
else
# otherwise, no need to worry, just create it
[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
skipped += objs.select { |o| o.errors.any? }.size
created += objs.select { |o| !o.errors.any? }.size
Expand Down
4 changes: 3 additions & 1 deletion db/seeds/categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
tag_set_id: <%= TagSet.unscoped.where(name: 'Main').first.id %>
use_for_hot_posts: true
use_for_advertisement: true
license_id: <%= License.unscoped.first.id %>

- name: Meta
short_wiki: Discussions and feedback about the site itself in Q&A format.
Expand All @@ -20,4 +21,5 @@
tag_set_id: <%= TagSet.unscoped.where(name: 'Meta').first.id %>
use_for_hot_posts: true
use_for_advertisement: false
color_code: bluegray
color_code: bluegray
license_id: <%= License.unscoped.first.id %>

0 comments on commit 7bcf244

Please sign in to comment.