Skip to content

Commit

Permalink
Merge pull request #1244 from ruby-china/fix-for-3.8
Browse files Browse the repository at this point in the history
Fix for 3.8
  • Loading branch information
huacnlee committed Dec 25, 2020
2 parents e96ffc1 + e8f68f7 commit 4ffd2f3
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 155 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN mkdir -p /home/app &&\
rm -rf /etc/nginx/conf.d/default.conf

ADD Gemfile Gemfile.lock package.json yarn.lock /home/app/homeland/
RUN gem install puma
RUN bundle config set deployment 'true' && bundle install && yarn &&\
find /home/app/homeland/vendor/bundle -name tmp -type d -exec rm -rf {} +
ADD . /home/app/homeland
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/topics_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def topic_follow_tag(topic, opts = {})
if opts[:class].present?
class_name += " " + opts[:class]
end
icon = content_tag("i", "", class: "fa fa-eye")
icon = content_tag("i", "", class: "fa fa-bell")
link_to(raw("#{icon} 订阅"), "#", "data-id" => topic.id, class: class_name)
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_editor_toolbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<% end %>
<a id="editor-upload-image" href="#" title="<%= t("common.editor_add_image") %>" class="nav-link upload-button">
<i class="upload-icon fa fa-image"></i>
<i class='loading fa fa-circle-o-notch fa-spin'></i>
<i class='loading fa fa-circle-notch fa-spin'></i>
</a>
<a href="#" class="nav-link preview" title="<%= t("common.editor_toolbar_preview") %>">
<%= icon_tag("eye") %>
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20201221082655_remove_follower_ids_from_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class RemoveFollowerIdsFromUsers < ActiveRecord::Migration[6.1]
def change
# Remove unused Array fields, they were instead by ActionStore
# ref: https://github.com/ruby-china/homeland/pull/857
remove_column :users, :follower_ids
end
end
36 changes: 34 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_11_19_010515) do
ActiveRecord::Schema.define(version: 2020_12_21_082655) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -37,6 +37,14 @@
t.index ["provider", "uid"], name: "index_authorizations_on_provider_and_uid"
end

create_table "commentable_pages", force: :cascade do |t|
t.string "name"
t.integer "user_id"
t.integer "comments_count", default: 0, null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "comments", id: :serial, force: :cascade do |t|
t.text "body", null: false
t.integer "user_id", null: false
Expand Down Expand Up @@ -75,6 +83,14 @@
t.index ["name"], name: "index_locations_on_name"
end

create_table "monkeys", force: :cascade do |t|
t.string "name"
t.integer "user_id"
t.integer "comments_count"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "nodes", id: :serial, force: :cascade do |t|
t.string "name", null: false
t.string "summary"
Expand Down Expand Up @@ -283,6 +299,15 @@
t.index ["user_id"], name: "index_team_users_on_user_id"
end

create_table "test_documents", force: :cascade do |t|
t.integer "user_id"
t.integer "reply_to_id"
t.integer "mentioned_user_ids", default: [], array: true
t.text "body"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "topics", id: :serial, force: :cascade do |t|
t.integer "user_id", null: false
t.integer "node_id", null: false
Expand Down Expand Up @@ -362,7 +387,6 @@
t.string "perishable_token", default: "", null: false
t.integer "topics_count", default: 0, null: false
t.integer "replies_count", default: 0, null: false
t.integer "follower_ids", default: [], array: true
t.string "type", limit: 20
t.integer "failed_attempts", default: 0, null: false
t.string "unlock_token"
Expand All @@ -378,4 +402,12 @@
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
end

create_table "walking_deads", force: :cascade do |t|
t.string "name"
t.string "tag"
t.datetime "deleted_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

end
5 changes: 5 additions & 0 deletions lib/homeland.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
require "homeland/version"
require "homeland/plugin"

unless ENV["RAILS_PRECOMPILE"]
# Preload Jieba
require "homeland/search"
end

module Homeland
cattr_reader :boot_at

Expand Down
5 changes: 2 additions & 3 deletions lib/homeland/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Search
attr_accessor :term, :terms

INVALID_CHARS = /[:()&!'"]/
JIEBA = JiebaRb::Segment.new

def initialize(term)
term = term.to_s.squish.gsub(INVALID_CHARS, "")
Expand All @@ -24,9 +25,7 @@ def query_results

class << self
def jieba
return @jieba if defined? @jieba

@jieba = JiebaRb::Segment.new
JIEBA
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/homeland/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Homeland
class << self
def version
"3.8.0"
"3.8.1"
end
end
end
37 changes: 37 additions & 0 deletions lib/tasks/memory.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

task memory: :environment do
require "homeland"
include ApplicationHelper
include ActionView::Helpers::OutputSafetyHelper
include ActionView::Helpers::TextHelper

str = Homeland::Markdown.example

a = []

puts "Starting to profile memory..."
b = {}
puts "Before =>"
print_memory

count = 5_000_000
step = (count / 100).to_i
count.times do |i|
sanitize_markdown(Homeland::Markdown.call(str))

if i % step == 0
print_memory
end
end

print_memory
puts GC.start
puts "After GC"
print_memory
end

def print_memory
rss = (`ps -eo pid,rss | grep #{Process.pid} | awk '{print $2}'`.to_i / 1024.0).round(1)
puts "rss: #{rss}mb live objects #{GC.stat[:heap_live_slots]}"
end
143 changes: 0 additions & 143 deletions lib/tasks/upgrade/next.rake

This file was deleted.

4 changes: 2 additions & 2 deletions test/helpers/topics_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class TopicsHelperTest < ActionView::TestCase
assert_equal "", topic_follow_tag(nil)

# was unfollow
assert_equal "<a data-id=\"#{topic.id}\" class=\"follow\" href=\"#\"><i class=\"fa fa-eye\"></i> 订阅</a>", topic_follow_tag(topic)
assert_html_equal %(<a data-id="#{topic.id}" class="follow" href="#"><i class="fa fa-bell"></i> 订阅</a>), topic_follow_tag(topic)

# was active
user.stub(:follow_topic?, true) do
assert_equal "<a data-id=\"#{topic.id}\" class=\"follow active\" href=\"#\"><i class=\"fa fa-eye\"></i> 订阅</a>", topic_follow_tag(topic)
assert_html_equal %(<a data-id="#{topic.id}" class="follow active" href="#"><i class="fa fa-bell"></i> 订阅</a>), topic_follow_tag(topic)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/models/reply_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class ReplyTest < ActiveSupport::TestCase

test ".notification_receiver_ids" do
mentioned_user_ids = [1, 2, 3]
user = create(:user, follower_ids: [2, 3, 5, 7, 9])
user = create(:user)
topic = create(:topic, user_id: 10)
reply = create(:reply, user: user, topic: topic, mentioned_user_ids: mentioned_user_ids)

Expand Down

0 comments on commit 4ffd2f3

Please sign in to comment.