Claude commited on
Commit
bf6465c
·
unverified ·
1 Parent(s): 018c37f

fix: 제출 버튼 3초 비활성화로 Rate Limiting 단순화

Browse files

DB 쿼리 방식 제거, session_state + disabled 파라미터로 교체.
제출 성공 후 3초간 버튼이 회색으로 비활성화됨.
name 'time' is not defined 오류도 함께 수정.

https://claude.ai/code/session_01BRbPoMBBfvgN58bGkNhmv7

Files changed (1) hide show
  1. app.py +3 -6
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import logging
 
2
 
3
  import streamlit as st
4
 
@@ -8,7 +9,6 @@ from db import (
8
  fetch_live_messages,
9
  fetch_topic_data,
10
  init_db,
11
- is_recent_submission,
12
  submit_opinion,
13
  using_service_role_key,
14
  )
@@ -140,7 +140,8 @@ with col_stt:
140
  height=120,
141
  )
142
 
143
- if st.button("의견 제출", use_container_width=True, type="primary"):
 
144
  input_ok, safe_input, input_error_code, input_error_message = validate_opinion_content(user_input, max_len=700)
145
  student_ok, safe_student_name, student_error_code, student_error_message = validate_student_name(student_name, max_len=MAX_STUDENT_NAME_LEN)
146
  student_number_ok, safe_student_number, _, student_number_error_message = validate_student_name(student_number, max_len=20)
@@ -153,15 +154,11 @@ if st.button("의견 제출", use_container_width=True, type="primary"):
153
  now = get_kst_now_str()
154
  author_role_for_submit = "교사" if user_role == "교사" else "학생"
155
  client_ip = get_client_ip()
156
- if is_recent_submission(supabase, room_name, safe_student_name):
157
- st.warning("⏳ 15초 후 다시 제출할 수 있습니다.")
158
- st.stop()
159
  insert_payload = {
160
  "room_name": room_name, "timestamp": now, "student_name": safe_student_name,
161
  "content": safe_input, "sentiment": sentiment, "author_role": author_role_for_submit,
162
  }
163
  if debate_ip_column_available() and client_ip:
164
- # inet 컬럼이므로 유효한 IP 형식 유지 — 마지막 옥텟만 0으로 익명화
165
  parts = client_ip.split(".")
166
  anonymized_ip = f"{parts[0]}.{parts[1]}.{parts[2]}.0" if len(parts) == 4 else None
167
  if anonymized_ip:
 
1
  import logging
2
+ import time
3
 
4
  import streamlit as st
5
 
 
9
  fetch_live_messages,
10
  fetch_topic_data,
11
  init_db,
 
12
  submit_opinion,
13
  using_service_role_key,
14
  )
 
140
  height=120,
141
  )
142
 
143
+ _submit_cooldown = time.time() - st.session_state.get('last_submit_ts', 0) < 3
144
+ if st.button("의견 제출", use_container_width=True, type="primary", disabled=_submit_cooldown):
145
  input_ok, safe_input, input_error_code, input_error_message = validate_opinion_content(user_input, max_len=700)
146
  student_ok, safe_student_name, student_error_code, student_error_message = validate_student_name(student_name, max_len=MAX_STUDENT_NAME_LEN)
147
  student_number_ok, safe_student_number, _, student_number_error_message = validate_student_name(student_number, max_len=20)
 
154
  now = get_kst_now_str()
155
  author_role_for_submit = "교사" if user_role == "교사" else "학생"
156
  client_ip = get_client_ip()
 
 
 
157
  insert_payload = {
158
  "room_name": room_name, "timestamp": now, "student_name": safe_student_name,
159
  "content": safe_input, "sentiment": sentiment, "author_role": author_role_for_submit,
160
  }
161
  if debate_ip_column_available() and client_ip:
 
162
  parts = client_ip.split(".")
163
  anonymized_ip = f"{parts[0]}.{parts[1]}.{parts[2]}.0" if len(parts) == 4 else None
164
  if anonymized_ip: