diff --git a/backend/app/controllers/gekanator_games_controller.rb b/backend/app/controllers/gekanator_games_controller.rb index c1b297e..4f378d0 100644 --- a/backend/app/controllers/gekanator_games_controller.rb +++ b/backend/app/controllers/gekanator_games_controller.rb @@ -27,12 +27,11 @@ class GekanatorGamesController < ApplicationController game = GekanatorGame.find_by(id: params[:id]) return head :not_found unless game - asked_ids = Array(game.answers).filter_map { |answer| - answer['questionId'] || answer[:questionId] - } + asked_ids = Array(game.answers).filter_map { |answer| answer_question_id(answer) } existing_example_ids = GekanatorQuestionExample.where(post_id: game.correct_post_id) .select(:gekanator_question_id) + # Direct examples only for now; post_similarity-based expansion is deferred. questions = GekanatorQuestion .accepted @@ -64,7 +63,7 @@ class GekanatorGamesController < ApplicationController answers = answer_params.map { |answer| { - question_id: answer.require(:question_id), + question_id: answer.require(:question_id).to_i, answer: answer.require(:answer) } } @@ -107,4 +106,13 @@ class GekanatorGamesController < ApplicationController priority_weight: question.priority_weight } end + + def answer_question_id answer + value = if answer.is_a?(Hash) + answer['question_id'].presence || answer[:question_id].presence || + answer['questionId'].presence || answer[:questionId].presence + end + + value&.to_s + end end diff --git a/backend/app/services/gekanator/question_suggestion_promoter.rb b/backend/app/services/gekanator/question_suggestion_promoter.rb index d99b1bd..d733a43 100644 --- a/backend/app/services/gekanator/question_suggestion_promoter.rb +++ b/backend/app/services/gekanator/question_suggestion_promoter.rb @@ -10,6 +10,7 @@ module Gekanator def call suggestion.with_lock do return promoted_question if suggestion.processed? + return suggestion if suggestion.answer == 'unknown' question = GekanatorQuestion.create!( text: suggestion.question_text, diff --git a/backend/db/schema.rb b/backend/db/schema.rb index a7d7dac..a873873 100644 --- a/backend/db/schema.rb +++ b/backend/db/schema.rb @@ -208,19 +208,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_10_000000) do t.index ["target_post_id"], name: "index_post_similarities_on_target_post_id" end - create_table "post_tag_sections", primary_key: ["post_id", "tag_id", "begin_ms"], charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| - t.bigint "post_id", null: false - t.bigint "tag_id", null: false - t.integer "begin_ms", null: false - t.integer "end_ms", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["post_id", "begin_ms"], name: "idx_post_tag_sections_post_id_begin_ms" - t.index ["tag_id"], name: "fk_rails_8be3847903" - t.check_constraint "`begin_ms` < `end_ms`", name: "chk_post_tag_sections_end_ms_after_begin_ms" - t.check_constraint "`begin_ms` >= 0", name: "chk_post_tag_sections_begin_ms_natural" - end - create_table "post_tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.bigint "post_id", null: false t.bigint "tag_id", null: false @@ -271,11 +258,8 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_10_000000) do t.datetime "original_created_before" t.datetime "updated_at", null: false t.integer "version_no", null: false - t.integer "video_ms" t.index ["uploaded_user_id"], name: "index_posts_on_uploaded_user_id" t.index ["url"], name: "index_posts_on_url", unique: true - t.index ["video_ms", "id"], name: "idx_posts_video_ms_id" - t.check_constraint "(`video_ms` is null) or (`video_ms` > 0)", name: "chk_posts_video_ms_positive" t.check_constraint "`version_no` > 0", name: "chk_posts_version_no_positive" end @@ -426,7 +410,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_10_000000) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["expires_at"], name: "index_theatre_watching_users_on_expires_at" - t.index ["theatre_id", "expires_at"], name: "idx_on_theatre_id_skip_expires_at_4c8de1dd42" t.index ["theatre_id", "expires_at"], name: "index_theatre_watching_users_on_theatre_id_and_expires_at" t.index ["theatre_id"], name: "index_theatre_watching_users_on_theatre_id" t.index ["user_id"], name: "index_theatre_watching_users_on_user_id" @@ -595,8 +578,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_10_000000) do add_foreign_key "post_implications", "posts", column: "parent_post_id" add_foreign_key "post_similarities", "posts" add_foreign_key "post_similarities", "posts", column: "target_post_id" - add_foreign_key "post_tag_sections", "posts" - add_foreign_key "post_tag_sections", "tags" add_foreign_key "post_tags", "posts" add_foreign_key "post_tags", "tags" add_foreign_key "post_tags", "users", column: "created_user_id" diff --git a/frontend/src/pages/GekanatorPage.tsx b/frontend/src/pages/GekanatorPage.tsx index 62c3963..3dcf84f 100644 --- a/frontend/src/pages/GekanatorPage.tsx +++ b/frontend/src/pages/GekanatorPage.tsx @@ -449,9 +449,12 @@ const previewAnswer = ({ const hardFilteredPosts = answer === 'unknown' ? posts - : posts.filter (post => expectedAnswerForQuestion (question, post) === answer) + : posts.filter (post => { + const expected = expectedAnswerForQuestion (question, post) + return expected === null || expected === 'unknown' || expected === answer + }) const nextPosts = - answer !== 'unknown' && hardFilteredPosts.length > 0 + hardFilteredPosts.length > 0 ? hardFilteredPosts : posts const nextScores = new Map (scores) @@ -1061,14 +1064,16 @@ const GekanatorPage: FC = () => { }}) const questionSuggestionMutation = useMutation ({ mutationFn: saveGekanatorQuestionSuggestion, - onSuccess: data => { + onSuccess: async data => { + await queryClient.refetchQueries ({ queryKey: gekanatorKeys.questions () }) setQuestionSuggestionCount (data.count) setQuestionSuggestion ('') setQuestionSuggestionAnswer ('yes') }}) const extraQuestionAnswersMutation = useMutation ({ mutationFn: saveGekanatorExtraQuestionAnswers, - onSuccess: () => { + onSuccess: async () => { + await queryClient.refetchQueries ({ queryKey: gekanatorKeys.questions () }) setExtraQuestionState ('saved') setPhase ('learned') }}) @@ -1544,7 +1549,12 @@ const GekanatorPage: FC = () => { ? <>グカカカカwwwww 洗澡鹿シーザオグカは何でもお見通し! : <>私は洗澡鹿シーザオグカ.質問から投稿を何でも当ててみせるよ const introLoading = isLoading || acceptedQuestionsLoading - const readyToStart = !(introLoading) && acceptedQuestionsFetched && posts.length > 0 + const readyToStart = + !(introLoading) + && acceptedQuestionsFetched + && posts.length > 0 + && !(error) + && !(acceptedQuestionsError) return (