From 4fc3ed927ce66cbcd289752207fcfb15d01978cf Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Thu, 5 Oct 2023 15:05:03 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=B6=E6=95=B0=E3=81=AE=E3=82=AD?= =?UTF-8?q?=E3=83=A3=E3=83=83=E3=82=B7=E3=83=A5=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecs/jskult-webapp/src/controller/bio_api.py | 3 +++ ecs/jskult-webapp/src/model/internal/session.py | 5 ++++- ecs/jskult-webapp/src/services/bio_view_service.py | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ecs/jskult-webapp/src/controller/bio_api.py b/ecs/jskult-webapp/src/controller/bio_api.py index 9107b109..982ef8d2 100644 --- a/ecs/jskult-webapp/src/controller/bio_api.py +++ b/ecs/jskult-webapp/src/controller/bio_api.py @@ -69,6 +69,9 @@ def search_bio_data( actions=[ UserSession.last_access_time.set(UserSession.new_last_access_time()), UserSession.record_expiration_time.set(UserSession.new_record_expiration_time()), + # 検索結果をキャッシュする + UserSession.bio_search_condition.set(bio_form.model_dump()), + UserSession.bio_search_count.set(bio_sales_lot_count), ] ) set_session(session) diff --git a/ecs/jskult-webapp/src/model/internal/session.py b/ecs/jskult-webapp/src/model/internal/session.py index 99233a1e..cba115a3 100644 --- a/ecs/jskult-webapp/src/model/internal/session.py +++ b/ecs/jskult-webapp/src/model/internal/session.py @@ -1,7 +1,8 @@ import datetime import uuid -from pynamodb.attributes import NumberAttribute, UnicodeAttribute +from pynamodb.attributes import (JSONAttribute, NumberAttribute, + UnicodeAttribute) from pynamodb.models import Model as DynamoDBTableModel from src.system_var import environment @@ -23,6 +24,8 @@ class UserSession(DynamoDBTableModel): csrf_token = UnicodeAttribute() last_access_time = NumberAttribute() record_expiration_time = NumberAttribute() + bio_search_condition = JSONAttribute(null=True, default=None) + bio_search_count = NumberAttribute(null=True, default=None) @classmethod def new_last_access_time(cls): diff --git a/ecs/jskult-webapp/src/services/bio_view_service.py b/ecs/jskult-webapp/src/services/bio_view_service.py index 1402bbd0..bbf01bcb 100644 --- a/ecs/jskult-webapp/src/services/bio_view_service.py +++ b/ecs/jskult-webapp/src/services/bio_view_service.py @@ -72,7 +72,13 @@ class BioViewService(BaseService): return display_bio_data def count_bio_data(self, search_params: BioModel, session: UserSession) -> int: - # 生物由来データの件数を取得 + # 検索値が前回検索時と変更がない場合、キャッシュした件数を返す + previous_search_params = session.bio_search_condition + current_search_params = search_params.model_dump() + if previous_search_params == current_search_params: + return session.bio_search_count + + # 生物由来データの件数をDBから取得 bio_sales_data_count = self.bio_sales_repository.fetch_count(parameter=search_params) return bio_sales_data_count