コミットを比較

..
3 コミット
作成者 SHA1 メッセージ 日付
みてるぞ b9d7c4fef5 #444 2026-11-08 01:56:45 +09:00
みてるぞ 10b3717886 Merge remote-tracking branch 'origin/main' into feature/444 2026-11-07 20:06:40 +09:00
みてるぞ 9e803d473a #444 2026-11-07 15:50:00 +09:00
13個のファイルの変更、25行の追加、350行の削除
-1
ファイルの表示
@@ -5,7 +5,6 @@ class MaterialVersionsController < ApplicationController
page = 1 if page < 1 page = 1 if page < 1
limit = 1 if limit < 1 limit = 1 if limit < 1
limit = 100 if limit > 100
offset = (page - 1) * limit offset = (page - 1) * limit
-1
ファイルの表示
@@ -14,7 +14,6 @@ class MaterialsController < ApplicationController
page = 1 if page < 1 page = 1 if page < 1
limit = 1 if limit < 1 limit = 1 if limit < 1
limit = 100 if limit > 100
offset = (page - 1) * limit offset = (page - 1) * limit
-1
ファイルの表示
@@ -15,7 +15,6 @@ class NicoTagsController < ApplicationController
page = 1 if page < 1 page = 1 if page < 1
limit = 1 if limit < 1 limit = 1 if limit < 1
limit = 100 if limit > 100
post_tag_max_sql = post_tag_max_sql =
PostExternalTag PostExternalTag
-1
ファイルの表示
@@ -11,7 +11,6 @@ class PostVersionsController < ApplicationController
page = 1 if page < 1 page = 1 if page < 1
limit = 1 if limit < 1 limit = 1 if limit < 1
limit = 100 if limit > 100
offset = (page - 1) * limit offset = (page - 1) * limit
-1
ファイルの表示
@@ -34,7 +34,6 @@ class PostsController < ApplicationController
page = 1 if page < 1 page = 1 if page < 1
limit = 1 if limit < 1 limit = 1 if limit < 1
limit = 100 if limit > 100
offset = (page - 1) * limit offset = (page - 1) * limit
-1
ファイルの表示
@@ -7,7 +7,6 @@ class TagVersionsController < ApplicationController
page = 1 if page < 1 page = 1 if page < 1
limit = 1 if limit < 1 limit = 1 if limit < 1
limit = 100 if limit > 100
offset = (page - 1) * limit offset = (page - 1) * limit
-1
ファイルの表示
@@ -33,7 +33,6 @@ class TagsController < ApplicationController
page = 1 if page < 1 page = 1 if page < 1
limit = 1 if limit < 1 limit = 1 if limit < 1
limit = 100 if limit > 100
offset = (page - 1) * limit offset = (page - 1) * limit
-2
ファイルの表示
@@ -2,7 +2,6 @@ class TheatreCommentsController < ApplicationController
def index def index
limit = params[:limit].to_i limit = params[:limit].to_i
limit = 20 if limit <= 0 limit = 20 if limit <= 0
limit = 100 if limit > 100
no_gt = params[:no_gt].to_i no_gt = params[:no_gt].to_i
no_gt = 0 if no_gt < 0 no_gt = 0 if no_gt < 0
@@ -10,7 +9,6 @@ class TheatreCommentsController < ApplicationController
comments = TheatreComment comments = TheatreComment
.where(theatre_id: params[:theatre_id]) .where(theatre_id: params[:theatre_id])
.where('no > ?', no_gt) .where('no > ?', no_gt)
.includes(:user)
.order(no: :desc) .order(no: :desc)
.limit(limit) .limit(limit)
+1 -2
ファイルの表示
@@ -2,7 +2,6 @@ class TheatreProgrammesController < ApplicationController
def index def index
limit = params[:limit].to_i limit = params[:limit].to_i
limit = 100 if limit <= 0 limit = 100 if limit <= 0
limit = 100 if limit > 100
position_gt = params[:position_gt].to_i position_gt = params[:position_gt].to_i
position_gt = 0 if position_gt < 0 position_gt = 0 if position_gt < 0
@@ -11,7 +10,7 @@ class TheatreProgrammesController < ApplicationController
.where(theatre_id: params[:theatre_id]) .where(theatre_id: params[:theatre_id])
.where('position > ?', position_gt) .where('position > ?', position_gt)
.includes(:post) .includes(:post)
.order(position: :desc) .order(position: :desc).limit(100)
.limit(limit) .limit(limit)
render json: programmes.map { |programme| render json: programmes.map { |programme|
-1
ファイルの表示
@@ -2,7 +2,6 @@ class TheatreSkipEventsController < ApplicationController
def index def index
limit = params[:limit].to_i limit = params[:limit].to_i
limit = 50 if limit <= 0 limit = 50 if limit <= 0
limit = 100 if limit > 100
events = events =
TheatreSkipEvent TheatreSkipEvent
-174
ファイルの表示
@@ -1,174 +0,0 @@
require 'rails_helper'
RSpec.describe 'List API limits', type: :request do
shared_examples 'a capped list' do |default_count, minimum_count, paginated|
def response_rows
body = json
body.is_a?(Array) ? body : body.fetch(collection_key)
end
it 'caps oversized limits at 100 and preserves the 100 boundary' do
get path, params: { locale: 'ja', limit: 100 }
expect(response).to have_http_status(:ok)
expect(response_rows.size).to eq(100)
boundary_rows = response_rows
[101, 10_000].each do |limit|
get path, params: { locale: 'ja', limit: }
expect(response).to have_http_status(:ok)
expect(response_rows).to eq(boundary_rows)
end
end
it 'preserves the default, nonpositive and small positive limits' do
get path, params: { locale: 'ja' }
expect(response).to have_http_status(:ok)
expect(response_rows.size).to eq(default_count)
[0, -1].each do |limit|
get path, params: { locale: 'ja', limit: }
expect(response).to have_http_status(:ok)
expect(response_rows.size).to eq(minimum_count)
end
get path, params: { locale: 'ja', limit: 2 }
expect(response).to have_http_status(:ok)
expect(response_rows.size).to eq(2)
end
if paginated
it 'uses the capped limit for page offsets and preserves total count' do
get path, params: { locale: 'ja', limit: 100 }
first_page = response_rows
expect(response).to have_http_status(:ok)
expect(json.fetch('count')).to eq(101)
get path, params: { locale: 'ja', limit: 100, page: 2 }
expect(response).to have_http_status(:ok)
expect(response_rows.size).to eq(1)
second_page = response_rows
expect(first_page & second_page).to be_empty
get path, params: { locale: 'ja', limit: 101, page: 2 }
expect(response).to have_http_status(:ok)
expect(response_rows).to eq(second_page)
expect(json.fetch('count')).to eq(101)
end
end
end
context 'posts' do
let(:path) { '/posts' }
let(:collection_key) { 'posts' }
before { create_list(:post, 101) }
include_examples 'a capped list', 20, 1, true
end
context 'tags' do
let(:path) { '/tags' }
let(:collection_key) { 'tags' }
before { create_list(:tag, 101) }
include_examples 'a capped list', 20, 1, true
end
context 'nico tags' do
let(:path) { '/tags/nico' }
let(:collection_key) { 'tags' }
before { create_list(:external_tag, 101) }
include_examples 'a capped list', 20, 1, true
end
context 'materials' do
let(:path) { '/materials' }
let(:collection_key) { 'materials' }
before do
101.times { |index| Material.create!(url: "https://example.com/material-#{ index }") }
end
include_examples 'a capped list', 20, 1, true
end
context 'post versions' do
let(:path) { '/posts/versions' }
let(:collection_key) { 'versions' }
let(:post) { create(:post) }
before do
101.times do |index|
PostVersion.create!(post:, version_no: index + 1, event_type: 'update',
url: post.url, tags: '', tags_json: [], parent_post_ids: '')
end
end
include_examples 'a capped list', 20, 1, true
end
context 'tag versions' do
let(:path) { '/tags/versions' }
let(:collection_key) { 'versions' }
let(:tag) { create(:tag) }
before do
101.times do |index|
TagVersion.create!(tag:, version_no: index + 1, event_type: 'update',
name: 'limit tag', category: 'general', aliases: '',
parent_tag_ids: '', names: {
ja: { name: 'limit tag', script_code: 'Jpan',
auto_generated: false, aliases: [] } })
end
end
include_examples 'a capped list', 20, 1, true
end
context 'material versions' do
let(:path) { '/materials/versions' }
let(:collection_key) { 'versions' }
let(:material) { Material.create!(url: 'https://example.com/material') }
before do
101.times do |index|
MaterialVersion.create!(material:, version_no: index + 1,
event_type: 'update', url: material.url)
end
end
include_examples 'a capped list', 20, 1, true
end
context 'theatre lists' do
let(:theatre) { create(:theatre) }
let(:post) { create(:post) }
context 'comments' do
let(:path) { "/theatres/#{ theatre.id }/comments" }
before { create_list(:theatre_comment, 101, theatre:, user: theatre.created_by_user) }
include_examples 'a capped list', 20, 20, false
end
context 'programmes' do
let(:path) { "/theatres/#{ theatre.id }/programmes" }
before do
101.times do |index|
TheatreProgramme.create!(theatre:, post:, position: index + 1)
end
end
include_examples 'a capped list', 100, 100, false
end
context 'skip events' do
let(:path) { "/theatres/#{ theatre.id }/skip_events" }
before do
101.times do |index|
TheatreSkipEvent.create!(theatre:, post:,
skipped_by_user: theatre.created_by_user,
created_at: Time.utc(2026, 1, 1) + index.seconds)
end
end
include_examples 'a capped list', 50, 50, false
end
end
end
-120
ファイルの表示
@@ -1,120 +0,0 @@
import { fireEvent, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { useLocation } from 'react-router-dom'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import TagSearch from '@/components/TagSearch'
import * as api from '@/lib/api'
import { buildTag } from '@/test/factories'
import { renderWithProviders } from '@/test/render'
const LocationOutput = () => {
const location = useLocation ()
return <output data-testid="location">{location.pathname}{location.search}</output>
}
const renderSearch = () => renderWithProviders (
<>
<TagSearch/>
<LocationOutput/>
</>, { route: '/ja/posts?page=3' })
describe ('TagSearch', () => {
beforeEach (() => {
vi.spyOn (api, 'apiGet').mockResolvedValue ([])
})
it ('searches through native submission without an Enter key event', () => {
renderSearch ()
const input = screen.getByRole<HTMLInputElement> ('textbox')
fireEvent.change (input, { target: { value: '虹夏 not:TEST type:or' } })
expect (input.form).toBeInstanceOf (HTMLFormElement)
fireEvent.submit (input.form!)
const query = new URLSearchParams ({ tags: '虹夏 not:test', match: 'any' })
expect (screen.getByTestId ('location')).toHaveTextContent (
`/ja/posts?${ query }`)
expect (input).toHaveValue ('虹夏 not:test type:or')
})
it ('requests a search action from the software keyboard', () => {
renderSearch ()
expect (screen.getByRole ('textbox')).toHaveAttribute ('enterkeyhint', 'search')
})
it ('searches through the form when Enter is pressed', async () => {
const user = userEvent.setup ()
renderSearch ()
await user.type (screen.getByRole ('textbox'), '虹夏{Enter}')
const query = new URLSearchParams ({ tags: '虹夏', match: 'all' })
expect (screen.getByTestId ('location')).toHaveTextContent (
`/ja/posts?${ query }`)
})
it.each ([
{ label: 'composition flag', composing: true, keyCode: 13 },
{ label: 'legacy IME code', composing: false, keyCode: 229 }]) (
'cancels confirmation Enter with $label', ({ composing, keyCode }) => {
renderSearch ()
const input = screen.getByRole ('textbox')
fireEvent.change (input, { target: { value: '虹夏' } })
const uncancelled = fireEvent.keyDown (input, {
key: 'Enter', isComposing: composing, keyCode })
expect (uncancelled).toBe (false)
expect (screen.getByTestId ('location')).toHaveTextContent ('/ja/posts?page=3')
expect (input).toHaveValue ('虹夏')
})
it ('cancels Enter throughout composition even without keyboard IME flags', () => {
renderSearch ()
const input = screen.getByRole ('textbox')
fireEvent.compositionStart (input)
fireEvent.change (input, { target: { value: '虹夏' } })
const uncancelled = fireEvent.keyDown (input, {
key: 'Enter', isComposing: false, keyCode: 13 })
expect (uncancelled).toBe (false)
expect (screen.getByTestId ('location')).toHaveTextContent ('/ja/posts?page=3')
expect (input).toHaveValue ('虹夏')
})
it ('blocks direct submission during composition and allows it after confirmation', () => {
renderSearch ()
const input = screen.getByRole<HTMLInputElement> ('textbox')
fireEvent.compositionStart (input)
fireEvent.change (input, { target: { value: '虹夏' } })
fireEvent.submit (input.form!)
expect (screen.getByTestId ('location')).toHaveTextContent ('/ja/posts?page=3')
expect (input).toHaveValue ('虹夏')
fireEvent.compositionEnd (input)
fireEvent.submit (input.form!)
const query = new URLSearchParams ({ tags: '虹夏', match: 'all' })
expect (screen.getByTestId ('location')).toHaveTextContent (
`/ja/posts?${ query }`)
})
it ('selects the active suggestion without submitting the form', async () => {
vi.mocked (api.apiGet).mockResolvedValue ([buildTag ({ name: '虹夏' })])
const user = userEvent.setup ()
renderSearch ()
await user.type (screen.getByRole ('textbox'), '虹')
await screen.findByText ('虹夏')
await user.keyboard ('{ArrowDown}{Enter}')
expect (screen.getByRole ('textbox')).toHaveValue ('虹夏 ')
expect (screen.getByTestId ('location')).toHaveTextContent ('/ja/posts?page=3')
expect (screen.queryByText ('虹夏')).not.toBeInTheDocument ()
})
})
+24 -44
ファイルの表示
@@ -1,6 +1,6 @@
// TODO: タグ入力系すべてに同様の処理あるため共通化する. // TODO: タグ入力系すべてに同様の処理あるため共通化する.
import { useEffect, useRef, useState } from 'react' import { useEffect, useState } from 'react'
import { useLocation } from 'react-router-dom' import { useLocation } from 'react-router-dom'
import { useLocale, useLocaleNavigate } from '@/lib/useLocale' import { useLocale, useLocaleNavigate } from '@/lib/useLocale'
@@ -10,7 +10,7 @@ import { inputClass } from '@/lib/utils'
import TagSearchBox from './TagSearchBox' import TagSearchBox from './TagSearchBox'
import type { ChangeEvent, FC, FormEvent, KeyboardEvent } from 'react' import type { ChangeEvent, FC, KeyboardEvent } from 'react'
import type { Tag } from '@/types' import type { Tag } from '@/types'
@@ -20,7 +20,6 @@ const TagSearch: FC = () => {
const locale = useLocale () const locale = useLocale ()
const location = useLocation () const location = useLocation ()
const navigate = useLocaleNavigate () const navigate = useLocaleNavigate ()
const compositionFlgRef = useRef (false)
const [activeIndex, setActiveIndex] = useState (-1) const [activeIndex, setActiveIndex] = useState (-1)
const [search, setSearch] = useState ('') const [search, setSearch] = useState ('')
@@ -75,34 +74,7 @@ const TagSearch: FC = () => {
setSuggestionsVsbl (false) setSuggestionsVsbl (false)
}, [locale]) }, [locale])
const handleSubmit = (ev: FormEvent<HTMLFormElement>) => {
ev.preventDefault ()
if (compositionFlgRef.current)
return
const parts = search.split (' ')
const match =
parts.map (t => t.toLowerCase ()).includes ('type:or') ? 'any' : 'all'
navigate (`/posts?${
(new URLSearchParams ({
tags: parts.map (t => t.toLowerCase ())
.filter (t => t !== 'type:or')
.join (' '),
match })).toString () }`)
setSuggestionsVsbl (false)
setRequest ({ query: '' })
}
const handleKeyDown = (ev: KeyboardEvent<HTMLInputElement>) => { const handleKeyDown = (ev: KeyboardEvent<HTMLInputElement>) => {
if (compositionFlgRef.current
|| ev.nativeEvent.isComposing
|| ev.nativeEvent.keyCode === 229)
{
if (ev.key === 'Enter')
ev.preventDefault ()
return
}
switch (ev.key) switch (ev.key)
{ {
case 'ArrowDown': case 'ArrowDown':
@@ -118,12 +90,13 @@ const TagSearch: FC = () => {
break break
case 'Enter': case 'Enter':
if (activeIndex < 0)
break
ev.preventDefault ()
{ {
const selected = suggestionsVsbl ? suggestions[activeIndex] : null const selected = suggestions[activeIndex]
if (selected == null) if (selected)
break handleTagSelect (selected)
ev.preventDefault ()
handleTagSelect (selected)
} }
break break
@@ -132,6 +105,20 @@ const TagSearch: FC = () => {
setSuggestionsVsbl (false) setSuggestionsVsbl (false)
break break
} }
if (ev.key === 'Enter' && (!(suggestionsVsbl) || activeIndex < 0))
{
const parts = search.split (' ')
const match = parts.map (t => t.toLowerCase ()).includes ('type:or') ? 'any' : 'all'
navigate (`/posts?${
(new URLSearchParams ({
tags: parts.map (t => t.toLowerCase ())
.filter (t => t !== 'type:or')
.join (' '),
match }))
.toString () }`)
setSuggestionsVsbl (false)
setRequest ({ query: '' })
}
} }
const handleTagSelect = (tag: Tag) => { const handleTagSelect = (tag: Tag) => {
@@ -157,9 +144,8 @@ const TagSearch: FC = () => {
}, [location.search]) }, [location.search])
return ( return (
<form onSubmit={handleSubmit} className="relative w-full"> <div className="relative w-full">
<input type="text" <input type="text"
enterKeyHint="search"
data-shortcut-focus-search="true" data-shortcut-focus-search="true"
placeholder={message ('labels.tagSearch').text} placeholder={message ('labels.tagSearch').text}
value={search} value={search}
@@ -167,18 +153,12 @@ const TagSearch: FC = () => {
onFocus={() => setSuggestionsVsbl (true)} onFocus={() => setSuggestionsVsbl (true)}
onBlur={() => setSuggestionsVsbl (false)} onBlur={() => setSuggestionsVsbl (false)}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
onCompositionStart={() => {
compositionFlgRef.current = true
}}
onCompositionEnd={() => {
compositionFlgRef.current = false
}}
className={inputClass (false, className={inputClass (false,
'px-3 py-2 dark:border-gray-600 dark:bg-gray-800 dark:text-white')}/> 'px-3 py-2 dark:border-gray-600 dark:bg-gray-800 dark:text-white')}/>
<TagSearchBox suggestions={suggestionsVsbl && suggestions.length ? suggestions : [] as Tag[]} <TagSearchBox suggestions={suggestionsVsbl && suggestions.length ? suggestions : [] as Tag[]}
activeIndex={activeIndex} activeIndex={activeIndex}
onSelect={handleTagSelect}/> onSelect={handleTagSelect}/>
</form>) </div>)
} }
export default TagSearch export default TagSearch