From 5cc47e42e11fdfe50a669c184c7f32a7db9f33f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BF=E3=81=A6=E3=82=8B=E3=81=9E?= Date: Wed, 26 Nov 2025 22:33:50 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E3=82=BF=E3=82=B0=E5=B8=8C?= =?UTF-8?q?=E6=9C=9B=E3=82=BF=E3=82=B0=E3=82=92=E6=96=B0=E8=A6=8F=E6=99=82?= =?UTF-8?q?=E3=81=AE=E3=81=BF=E3=81=AB=E3=81=99=E3=82=8B=EF=BC=88#128?= =?UTF-8?q?=EF=BC=89=20(#145)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #128 完了 Co-authored-by: miteruzo Reviewed-on: https://git.miteruzo.com/miteruzo/btrc-hub/pulls/145 --- backend/app/controllers/posts_controller.rb | 3 ++- backend/app/models/tag.rb | 2 +- backend/lib/tasks/sync_nico.rake | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/app/controllers/posts_controller.rb b/backend/app/controllers/posts_controller.rb index 6877c70..b6e7d5d 100644 --- a/backend/app/controllers/posts_controller.rb +++ b/backend/app/controllers/posts_controller.rb @@ -110,7 +110,8 @@ class PostsController < ApplicationController original_created_before = params[:original_created_before] post = Post.find(params[:id].to_i) - tags = post.tags.where(category: 'nico').to_a + Tag.normalise_tags(tag_names) + tags = post.tags.where(category: 'nico').to_a + + Tag.normalise_tags(tag_names, with_tagme: false) if post.update(title:, tags:, original_created_from:, original_created_before:) render json: post.as_json(include: { tags: { only: [:id, :name, :category, :post_count] } }), status: :ok diff --git a/backend/app/models/tag.rb b/backend/app/models/tag.rb index 137afff..e80baff 100644 --- a/backend/app/models/tag.rb +++ b/backend/app/models/tag.rb @@ -57,7 +57,7 @@ class Tag < ApplicationRecord end end end - tags << Tag.tagme if with_tagme && tags.size < 20 && tags.none?(Tag.tagme) + tags << Tag.tagme if with_tagme && tags.size < 10 && tags.none?(Tag.tagme) tags.uniq end diff --git a/backend/lib/tasks/sync_nico.rake b/backend/lib/tasks/sync_nico.rake index a8601c5..9fe28fb 100644 --- a/backend/lib/tasks/sync_nico.rake +++ b/backend/lib/tasks/sync_nico.rake @@ -51,7 +51,7 @@ namespace :nico do end tags_to_add.concat([tag] + tag.linked_tags) end - tags_to_add << Tag.tagme if post.tags.size < 20 + tags_to_add << Tag.tagme if post.tags.size < 10 tags_to_add << Tag.bot post.tags = (post.tags + tags_to_add).uniq end From 8a126e2e92037fcb6575f6934df44629784c2c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BF=E3=81=A6=E3=82=8B=E3=81=9E?= Date: Wed, 26 Nov 2025 23:48:45 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=81=AB=20IP=20=E3=82=A2=E3=83=89=E3=83=AC=E3=82=B9=E3=82=92?= =?UTF-8?q?=E7=B4=90=E3=81=A5=E3=81=91=EF=BC=88#29=EF=BC=89=20(#165)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #29 対応完了 Co-authored-by: miteruzo Reviewed-on: https://git.miteruzo.com/miteruzo/btrc-hub/pulls/165 --- backend/app/controllers/users_controller.rb | 13 ++++++----- backend/app/models/user.rb | 1 - ...rename_ip_adress_column_to_ip_addresses.rb | 5 +++++ backend/db/schema.rb | 22 +++++++++++++++++-- 4 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 backend/db/migrate/20251126231500_rename_ip_adress_column_to_ip_addresses.rb diff --git a/backend/app/controllers/users_controller.rb b/backend/app/controllers/users_controller.rb index 8658a5f..4ee4836 100644 --- a/backend/app/controllers/users_controller.rb +++ b/backend/app/controllers/users_controller.rb @@ -6,12 +6,15 @@ class UsersController < ApplicationController end def verify + ip_bin = IPAddr.new(request.remote_ip).hton + ip_address = IpAddress.find_or_create_by!(ip_address: ip_bin) + user = User.find_by(inheritance_code: params[:code]) - render json: if user - { valid: true, user: user.slice(:id, :name, :inheritance_code, :role) } - else - { valid: false } - end + return render json: { valid: false } unless user + + UserIp.find_or_create_by!(user:, ip_address:) + + render json: { valid: true, user: user.slice(:id, :name, :inheritance_code, :role) } end def renew diff --git a/backend/app/models/user.rb b/backend/app/models/user.rb index 830d383..ede464a 100644 --- a/backend/app/models/user.rb +++ b/backend/app/models/user.rb @@ -8,7 +8,6 @@ class User < ApplicationRecord has_many :posts has_many :settings - has_many :ip_addresses has_many :user_ips, dependent: :destroy has_many :ip_addresses, through: :user_ips has_many :user_post_views, dependent: :destroy diff --git a/backend/db/migrate/20251126231500_rename_ip_adress_column_to_ip_addresses.rb b/backend/db/migrate/20251126231500_rename_ip_adress_column_to_ip_addresses.rb new file mode 100644 index 0000000..60f78e6 --- /dev/null +++ b/backend/db/migrate/20251126231500_rename_ip_adress_column_to_ip_addresses.rb @@ -0,0 +1,5 @@ +class RenameIpAdressColumnToIpAddresses < ActiveRecord::Migration[8.0] + def change + rename_column :ip_addresses, :ip_adress, :ip_address + end +end diff --git a/backend/db/schema.rb b/backend/db/schema.rb index 4d5cfd6..b8210d8 100644 --- a/backend/db/schema.rb +++ b/backend/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_09_09_075500) do +ActiveRecord::Schema[8.0].define(version: 2025_11_26_231500) do create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -40,7 +40,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_09_075500) do end create_table "ip_addresses", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.binary "ip_adress", limit: 16, null: false + t.binary "ip_address", limit: 16, null: false t.boolean "banned", default: false, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -70,9 +70,16 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_09_075500) do t.bigint "deleted_user_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.datetime "discarded_at" + t.virtual "is_active", type: :boolean, as: "(`discarded_at` is null)", stored: true + t.virtual "active_unique_key", type: :string, as: "(case when (`discarded_at` is null) then concat(`post_id`,_utf8mb4':',`tag_id`) else NULL end)", stored: true + t.index ["active_unique_key"], name: "idx_post_tags_active_unique", unique: true t.index ["created_user_id"], name: "index_post_tags_on_created_user_id" t.index ["deleted_user_id"], name: "index_post_tags_on_deleted_user_id" + t.index ["discarded_at"], name: "index_post_tags_on_discarded_at" + t.index ["post_id", "discarded_at"], name: "index_post_tags_on_post_id_and_discarded_at" t.index ["post_id"], name: "index_post_tags_on_post_id" + t.index ["tag_id", "discarded_at"], name: "index_post_tags_on_tag_id_and_discarded_at" t.index ["tag_id"], name: "index_post_tags_on_tag_id" end @@ -107,6 +114,15 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_09_075500) do t.index ["tag_id"], name: "index_tag_aliases_on_tag_id" end + create_table "tag_implications", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.bigint "tag_id", null: false + t.bigint "parent_tag_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["parent_tag_id"], name: "index_tag_implications_on_parent_tag_id" + t.index ["tag_id"], name: "index_tag_implications_on_tag_id" + end + create_table "tag_similarities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.bigint "tag_id", null: false t.bigint "target_tag_id", null: false @@ -176,6 +192,8 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_09_075500) do add_foreign_key "posts", "users", column: "uploaded_user_id" add_foreign_key "settings", "users" add_foreign_key "tag_aliases", "tags" + add_foreign_key "tag_implications", "tags" + add_foreign_key "tag_implications", "tags", column: "parent_tag_id" add_foreign_key "tag_similarities", "tags" add_foreign_key "tag_similarities", "tags", column: "target_tag_id" add_foreign_key "user_ips", "ip_addresses" From 06cd569fc58cebda10b2649f942e53b85cbe055d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BF=E3=81=A6=E3=82=8B=E3=81=9E?= Date: Sun, 7 Dec 2025 12:28:43 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E3=83=8B=E3=82=B3=E3=82=BF=E3=82=B0?= =?UTF-8?q?=E4=B8=80=E6=8B=AC=E9=80=A3=E6=90=BA=E3=81=AE=E5=89=8A=E9=99=A4?= =?UTF-8?q?=EF=BC=88#166=EF=BC=89=20(#167)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'backend/lib/tasks/link_nico.rake' を削除 Reviewed-on: https://git.miteruzo.com/miteruzo/btrc-hub/pulls/167 --- backend/lib/tasks/link_nico.rake | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 backend/lib/tasks/link_nico.rake diff --git a/backend/lib/tasks/link_nico.rake b/backend/lib/tasks/link_nico.rake deleted file mode 100644 index 0c02f48..0000000 --- a/backend/lib/tasks/link_nico.rake +++ /dev/null @@ -1,12 +0,0 @@ -namespace :nico do - desc 'ニコタグ連携' - task link: :environment do - Post.find_each do |post| - tags = post.tags.where(category: 'nico') - tags.each do |tag| - post.tags.concat(tag.linked_tags) if tag.linked_tags.present? - end - post.tags = post.tags.to_a.uniq - end - end -end