@@ -244,25 +244,31 @@ async fn upsert_problems(
244244 new_problems : Vec < Problem > ,
245245) -> Result < usize , DbErr > {
246246 for problem in & new_problems {
247- // Check if problem already exists; only insert if it doesn't.
248- // This prevents overwriting existing problem metadata (e.g. original contest_id)
249- // when the same problem_id appears in multiple contests (ADT reuses ABC problems).
250- // In other words: this is an ADT-specific countermeasure to keep the first-seen
251- // contest as the canonical one for the problem.
252- let existing = sql_entities:: problems:: Entity :: find_by_id ( problem. id . clone ( ) )
253- . one ( db)
254- . await ?;
247+ // Insert into problems table
248+ let title = problem. title ( ) ;
249+ let model = sql_entities:: problems:: ActiveModel {
250+ id : Set ( problem. id . clone ( ) ) ,
251+ contest_id : Set ( problem. contest_id . clone ( ) ) ,
252+ problem_index : Set ( problem. problem_index . clone ( ) ) ,
253+ name : Set ( problem. name . clone ( ) ) ,
254+ title : Set ( title) ,
255+ } ;
255256
256- if existing. is_none ( ) {
257- let title = problem. title ( ) ;
258- let model = sql_entities:: problems:: ActiveModel {
259- id : Set ( problem. id . clone ( ) ) ,
260- contest_id : Set ( problem. contest_id . clone ( ) ) ,
261- problem_index : Set ( problem. problem_index . clone ( ) ) ,
262- name : Set ( problem. name . clone ( ) ) ,
263- title : Set ( title) ,
264- } ;
257+ // ADTの問題は全てABCで既出であり、これらは同一視したい。
258+ // そのまま通すと問題情報がABCからADTに上書きされてしまうので、ADTの問題はproblemsには入れないようにする。
259+ // (ただしcontest_problemには入れる)
260+ if !problem. contest_id . starts_with ( "adt" ) {
265261 sql_entities:: problems:: Entity :: insert ( model)
262+ . on_conflict (
263+ OnConflict :: column ( sql_entities:: problems:: Column :: Id )
264+ . update_columns ( [
265+ sql_entities:: problems:: Column :: ContestId ,
266+ sql_entities:: problems:: Column :: ProblemIndex ,
267+ sql_entities:: problems:: Column :: Name ,
268+ sql_entities:: problems:: Column :: Title ,
269+ ] )
270+ . to_owned ( ) ,
271+ )
266272 . exec ( db)
267273 . await ?;
268274 }
0 commit comments