fix: resolver problemas identificados no code review

Correções de segurança:
- SQL Injection: usar prepared statements em ranking_repository.py
- Validação de entrada para parâmetros page/size

Correções de bugs:
- Bônus de continuidade: 15→20 pts para 8+ anos (conforme especificação)
- Memory leak: limpar _consultores após processamento do ranking

Melhorias de robustez:
- Substituir bare except por exceções específicas
- Threading.Lock para padrão singleton thread-safe
- Pool Oracle com configuração otimizada (timeout/getmode)
- ES client com timeouts diferenciados e verificação is_closed
- Logging para tipos de coordenação desconhecidos

Correções frontend:
- Polling com timeout máximo de 5 minutos
- useEffect cleanup para setTimeout
- React.memo e useMemo para otimização de performance
This commit is contained in:
Frederico Castro
2025-12-15 07:11:28 -03:00
parent d639b82087
commit df3d03d3b2
10 changed files with 91 additions and 37 deletions

View File

@@ -48,7 +48,7 @@ async def carregar_ranking_do_oracle() -> int:
for c in consultores:
try:
detalhes = json.loads(c.json_detalhes) if isinstance(c.json_detalhes, str) else c.json_detalhes or {}
except:
except (json.JSONDecodeError, TypeError, ValueError):
detalhes = {}
entries.append(
@@ -120,13 +120,13 @@ async def lifespan(app: FastAPI):
if scheduler:
try:
scheduler.parar()
except:
except Exception:
pass
if oracle_client:
try:
oracle_client.close()
except:
except Exception:
pass
await es_client.close()

View File

@@ -1,3 +1,6 @@
import threading
from typing import Optional
from ...infrastructure.elasticsearch.client import ElasticsearchClient
from ...infrastructure.repositories.consultor_repository_impl import ConsultorRepositoryImpl
from ...infrastructure.oracle.client import OracleClient
@@ -15,22 +18,25 @@ es_client = ElasticsearchClient(
verify_ssl=settings.ES_VERIFY_SSL,
)
oracle_client = OracleClient(
oracle_client: Optional[OracleClient] = OracleClient(
user=settings.ORACLE_LOCAL_USER,
password=settings.ORACLE_LOCAL_PASSWORD,
dsn=settings.ORACLE_LOCAL_DSN,
) if settings.ORACLE_LOCAL_USER and settings.ORACLE_LOCAL_DSN else None
ranking_oracle_repo = RankingOracleRepository(oracle_client) if oracle_client else None
ranking_oracle_repo: Optional[RankingOracleRepository] = RankingOracleRepository(oracle_client) if oracle_client else None
_repository: ConsultorRepositoryImpl = None
_processar_job: ProcessarRankingJob = None
_repository: Optional[ConsultorRepositoryImpl] = None
_processar_job: Optional[ProcessarRankingJob] = None
_lock = threading.Lock()
def get_repository() -> ConsultorRepositoryImpl:
global _repository
if _repository is None:
_repository = ConsultorRepositoryImpl(es_client=es_client, oracle_client=oracle_client)
with _lock:
if _repository is None:
_repository = ConsultorRepositoryImpl(es_client=es_client, oracle_client=oracle_client)
return _repository
@@ -49,9 +55,11 @@ def get_ranking_oracle_repo() -> RankingOracleRepository:
def get_processar_job() -> ProcessarRankingJob:
global _processar_job
if _processar_job is None:
_processar_job = ProcessarRankingJob(
es_client=es_client,
ranking_store=ranking_store,
ranking_oracle_repo=ranking_oracle_repo,
)
with _lock:
if _processar_job is None:
_processar_job = ProcessarRankingJob(
es_client=es_client,
ranking_store=ranking_store,
ranking_oracle_repo=ranking_oracle_repo,
)
return _processar_job