Skip to content

Commit 1423799

Browse files
CopilotMte90
andcommitted
Remove deprecated _retry_on_db_locked function and refactor to use decorator
Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com>
1 parent ba30044 commit 1423799

File tree

1 file changed

+35
-46
lines changed

1 file changed

+35
-46
lines changed

db/operations.py

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,6 @@ def _ensure_projects_dir():
386386
raise
387387

388388

389-
def _retry_on_db_locked(func, *args, max_retries=DB_RETRY_COUNT, **kwargs):
390-
"""
391-
Retry a database operation if it's locked.
392-
393-
DEPRECATED: Use @retry_on_db_locked decorator from utils.retry instead.
394-
This function is maintained for backward compatibility.
395-
"""
396-
# Use the retry decorator from utils.retry
397-
decorated_func = retry_on_db_locked(max_retries=max_retries, base_delay=DB_RETRY_DELAY)(func)
398-
return decorated_func(*args, **kwargs)
399-
400-
401389
def _get_project_id(project_path: str) -> str:
402390
"""Generate a stable project ID from the project path."""
403391
import hashlib
@@ -416,40 +404,34 @@ def _get_projects_registry_path() -> str:
416404
return os.path.join(PROJECTS_DIR, "registry.db")
417405

418406

407+
@retry_on_db_locked(max_retries=DB_RETRY_COUNT, base_delay=DB_RETRY_DELAY)
419408
def _init_registry_db():
420409
"""Initialize the projects registry database with proper configuration."""
421410
registry_path = _get_projects_registry_path()
422411

423-
def _init():
424-
conn = _get_connection(registry_path)
425-
try:
426-
cur = conn.cursor()
427-
cur.execute(
428-
"""
429-
CREATE TABLE IF NOT EXISTS projects (
430-
id TEXT PRIMARY KEY,
431-
name TEXT NOT NULL,
432-
path TEXT NOT NULL UNIQUE,
433-
database_path TEXT NOT NULL,
434-
created_at TEXT DEFAULT (datetime('now')),
435-
last_indexed_at TEXT,
436-
status TEXT DEFAULT 'created',
437-
settings TEXT
438-
)
439-
"""
440-
)
441-
conn.commit()
442-
except Exception as e:
443-
_LOG.error(f"Failed to initialize registry database: {e}")
444-
raise
445-
finally:
446-
conn.close()
447-
412+
conn = _get_connection(registry_path)
448413
try:
449-
_retry_on_db_locked(_init)
414+
cur = conn.cursor()
415+
cur.execute(
416+
"""
417+
CREATE TABLE IF NOT EXISTS projects (
418+
id TEXT PRIMARY KEY,
419+
name TEXT NOT NULL,
420+
path TEXT NOT NULL UNIQUE,
421+
database_path TEXT NOT NULL,
422+
created_at TEXT DEFAULT (datetime('now')),
423+
last_indexed_at TEXT,
424+
status TEXT DEFAULT 'created',
425+
settings TEXT
426+
)
427+
"""
428+
)
429+
conn.commit()
450430
except Exception as e:
451-
_LOG.error(f"Failed to initialize registry after retries: {e}")
431+
_LOG.error(f"Failed to initialize registry database: {e}")
452432
raise
433+
finally:
434+
conn.close()
453435

454436

455437
def create_project(project_path: str, name: Optional[str] = None) -> Dict[str, Any]:
@@ -510,6 +492,7 @@ def create_project(project_path: str, name: Optional[str] = None) -> Dict[str, A
510492

511493
registry_path = _get_projects_registry_path()
512494

495+
@retry_on_db_locked(max_retries=DB_RETRY_COUNT, base_delay=DB_RETRY_DELAY)
513496
def _create():
514497
conn = _get_connection(registry_path)
515498
try:
@@ -551,7 +534,7 @@ def _create():
551534
conn.close()
552535

553536
try:
554-
result = _retry_on_db_locked(_create)
537+
result = _create()
555538
return result
556539
except Exception as e:
557540
_LOG.error(f"Failed to create project: {e}")
@@ -571,6 +554,7 @@ def get_project(project_path: str) -> Optional[Dict[str, Any]]:
571554

572555
registry_path = _get_projects_registry_path()
573556

557+
@retry_on_db_locked(max_retries=DB_RETRY_COUNT, base_delay=DB_RETRY_DELAY)
574558
def _get():
575559
conn = _get_connection(registry_path)
576560
try:
@@ -584,7 +568,7 @@ def _get():
584568
finally:
585569
conn.close()
586570

587-
return _retry_on_db_locked(_get)
571+
return _get()
588572

589573

590574
def get_project_by_id(project_id: str) -> Optional[Dict[str, Any]]:
@@ -599,6 +583,7 @@ def get_project_by_id(project_id: str) -> Optional[Dict[str, Any]]:
599583

600584
registry_path = _get_projects_registry_path()
601585

586+
@retry_on_db_locked(max_retries=DB_RETRY_COUNT, base_delay=DB_RETRY_DELAY)
602587
def _get():
603588
conn = _get_connection(registry_path)
604589
try:
@@ -612,7 +597,7 @@ def _get():
612597
finally:
613598
conn.close()
614599

615-
return _retry_on_db_locked(_get)
600+
return _get()
616601

617602

618603
def list_projects() -> List[Dict[str, Any]]:
@@ -621,6 +606,7 @@ def list_projects() -> List[Dict[str, Any]]:
621606

622607
registry_path = _get_projects_registry_path()
623608

609+
@retry_on_db_locked(max_retries=DB_RETRY_COUNT, base_delay=DB_RETRY_DELAY)
624610
def _list():
625611
conn = _get_connection(registry_path)
626612
try:
@@ -631,7 +617,7 @@ def _list():
631617
finally:
632618
conn.close()
633619

634-
return _retry_on_db_locked(_list)
620+
return _list()
635621

636622

637623
def update_project_status(project_id: str, status: str, last_indexed_at: Optional[str] = None):
@@ -640,6 +626,7 @@ def update_project_status(project_id: str, status: str, last_indexed_at: Optiona
640626

641627
registry_path = _get_projects_registry_path()
642628

629+
@retry_on_db_locked(max_retries=DB_RETRY_COUNT, base_delay=DB_RETRY_DELAY)
643630
def _update():
644631
conn = _get_connection(registry_path)
645632
try:
@@ -658,7 +645,7 @@ def _update():
658645
finally:
659646
conn.close()
660647

661-
_retry_on_db_locked(_update)
648+
_update()
662649
# Invalidate cache after update
663650
project_cache.invalidate(f"project:id:{project_id}")
664651

@@ -670,6 +657,7 @@ def update_project_settings(project_id: str, settings: Dict[str, Any]):
670657

671658
registry_path = _get_projects_registry_path()
672659

660+
@retry_on_db_locked(max_retries=DB_RETRY_COUNT, base_delay=DB_RETRY_DELAY)
673661
def _update():
674662
conn = _get_connection(registry_path)
675663
try:
@@ -682,7 +670,7 @@ def _update():
682670
finally:
683671
conn.close()
684672

685-
_retry_on_db_locked(_update)
673+
_update()
686674
# Invalidate cache after update
687675
project_cache.invalidate(f"project:id:{project_id}")
688676

@@ -704,6 +692,7 @@ def delete_project(project_id: str):
704692

705693
registry_path = _get_projects_registry_path()
706694

695+
@retry_on_db_locked(max_retries=DB_RETRY_COUNT, base_delay=DB_RETRY_DELAY)
707696
def _delete():
708697
conn = _get_connection(registry_path)
709698
try:
@@ -713,7 +702,7 @@ def _delete():
713702
finally:
714703
conn.close()
715704

716-
_retry_on_db_locked(_delete)
705+
_delete()
717706
# Invalidate cache after deletion
718707
project_cache.invalidate(f"project:id:{project_id}")
719708
if project.get("path"):

0 commit comments

Comments
 (0)