Skip to content

Commit 187712f

Browse files
DeanChensjcopybara-github
authored andcommitted
fix: Remove excessive db call to update state table.
PiperOrigin-RevId: 764375522
1 parent 4d97f92 commit 187712f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/google/adk/sessions/database_session_service.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from __future__ import annotations
15+
1416
import copy
1517
from datetime import datetime
1618
import json
@@ -512,15 +514,16 @@ async def append_event(self, session: Session, event: Event) -> Event:
512514
_extract_state_delta(event.actions.state_delta)
513515
)
514516

515-
# Merge state
516-
app_state.update(app_state_delta)
517-
user_state.update(user_state_delta)
518-
session_state.update(session_state_delta)
519-
520-
# Update storage
521-
storage_app_state.state = app_state
522-
storage_user_state.state = user_state
523-
storage_session.state = session_state
517+
# Merge state and update storage
518+
if app_state_delta:
519+
app_state.update(app_state_delta)
520+
storage_app_state.state = app_state
521+
if user_state_delta:
522+
user_state.update(user_state_delta)
523+
storage_user_state.state = user_state
524+
if session_state_delta:
525+
session_state.update(session_state_delta)
526+
storage_session.state = session_state
524527

525528
storage_event = StorageEvent(
526529
id=event.id,

0 commit comments

Comments
 (0)