重构时序数据库连接逻辑,移除冗余代码

This commit is contained in:
2026-03-13 16:18:11 +08:00
parent c137adedad
commit 1673396e1a
5 changed files with 50 additions and 53 deletions
+11 -11
View File
@@ -6,9 +6,9 @@ import psycopg
from psycopg import sql
from psycopg.rows import dict_row
import time
from app.core.config import get_timescaledb_pgconn_string
from app.infra.db.timescaledb.repositories.scheme import SchemeRepository
from app.infra.db.timescaledb.repositories.realtime import RealtimeRepository
import app.infra.db.timescaledb.timescaledb_info as timescaledb_info
from app.infra.db.timescaledb.repositories.scada import ScadaRepository
@@ -25,9 +25,9 @@ class InternalStorage:
for attempt in range(max_retries):
try:
conn_string = (
timescaledb_info.get_pgconn_string(db_name=db_name)
get_timescaledb_pgconn_string(db_name=db_name)
if db_name
else timescaledb_info.get_pgconn_string()
else get_timescaledb_pgconn_string()
)
with psycopg.Connection.connect(conn_string) as conn:
RealtimeRepository.store_realtime_simulation_result_sync(
@@ -56,9 +56,9 @@ class InternalStorage:
for attempt in range(max_retries):
try:
conn_string = (
timescaledb_info.get_pgconn_string(db_name=db_name)
get_timescaledb_pgconn_string(db_name=db_name)
if db_name
else timescaledb_info.get_pgconn_string()
else get_timescaledb_pgconn_string()
)
with psycopg.Connection.connect(conn_string) as conn:
SchemeRepository.store_scheme_simulation_result_sync(
@@ -97,9 +97,9 @@ class InternalQueries:
for attempt in range(max_retries):
try:
conn_string = (
timescaledb_info.get_pgconn_string(db_name=db_name)
get_timescaledb_pgconn_string(db_name=db_name)
if db_name
else timescaledb_info.get_pgconn_string()
else get_timescaledb_pgconn_string()
)
with psycopg.Connection.connect(conn_string) as conn:
rows = ScadaRepository.get_scada_by_ids_time_range_sync(
@@ -144,9 +144,9 @@ class InternalQueries:
for attempt in range(max_retries):
try:
conn_string = (
timescaledb_info.get_pgconn_string(db_name=db_name)
get_timescaledb_pgconn_string(db_name=db_name)
if db_name
else timescaledb_info.get_pgconn_string()
else get_timescaledb_pgconn_string()
)
with psycopg.Connection.connect(conn_string) as conn:
rows = ScadaRepository.get_scada_by_ids_time_range_sync(
@@ -257,9 +257,9 @@ class InternalQueries:
for attempt in range(max_retries):
try:
conn_string = (
timescaledb_info.get_pgconn_string(db_name=db_name)
get_timescaledb_pgconn_string(db_name=db_name)
if db_name
else timescaledb_info.get_pgconn_string()
else get_timescaledb_pgconn_string()
)
with psycopg.Connection.connect(conn_string) as conn:
with conn.cursor(row_factory=dict_row) as cur: