mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-04-23 14:40:03 +08:00
Fix: Optimized the get_by_id method to resolve the issue of missing exceptions and improve query performance (#6320)
Fix: Optimized the get_by_id method to resolve the issue of missing exceptions and improve query performance ### What problem does this PR solve? Optimized the get_by_id method to resolve the issue of missing exceptions and improve query performance. Optimization details: 1. The original method used a custom query method that required concatenating SQL, which impacted performance. 2. The query method returned a list, which needed to be accessed by index, posing a risk of index out-of-bounds errors. 3. The original method used except Exception to catch all errors, which is not a best practice in Python programming and may lead to missing exceptions. The get_or_none method accurately catches DoesNotExist errors while allowing other errors to be raised normally. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [x] Performance Improvement
This commit is contained in:
parent
ca9c3e59fa
commit
7f80d7304d
@ -225,11 +225,10 @@ class CommonService:
|
|||||||
# pid: Record ID
|
# pid: Record ID
|
||||||
# Returns:
|
# Returns:
|
||||||
# Tuple of (success, record)
|
# Tuple of (success, record)
|
||||||
try:
|
obj = cls.model.get_or_none(cls.model.id == pid)
|
||||||
obj = cls.model.query(id=pid)[0]
|
if obj:
|
||||||
return True, obj
|
return True, obj
|
||||||
except Exception:
|
return False, None
|
||||||
return False, None
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@DB.connection_context()
|
@DB.connection_context()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user