Local Scan Request Cache Documentation
This code implements a local in-memory cache for attendance scan requests and their approvals, aiming to optimize performance by reducing database reads.
LocalScanRequest
struct
type LocalScanRequest struct {
wg sync.WaitGroup
mtx sync.Mutex
dao *daos.Dao
ScanRequest []entity.AttendanceRequestTable
IndexedScanRequest map[string]*entity.AttendanceRequestTable
ScanRequestRead bool
ScanRequestApproval []entity.AttendanceRequestApprovalTable
MapScanRequestApproval map[string][]*entity.AttendanceRequestApprovalTable // key = ScanRequest.ID
ScanRequestApprovalRead bool
StartDate time.Time // for read again
EndDate time.Time // for read again
CompanyID string // for read again
}
wg sync.WaitGroup
: Manages asynchronous database operations.mtx sync.Mutex
: Ensures thread-safe access to the cache.dao *daos.Dao
: The PocketBase DAO.ScanRequest []entity.AttendanceRequestTable
: Slice of scan requests.IndexedScanRequest map[string]*entity.AttendanceRequestTable
: Scan requests indexed by ID.ScanRequestRead bool
: Indicates if scan requests have been read from the database.ScanRequestApproval []entity.AttendanceRequestApprovalTable
: Slice of scan request approvals.MapScanRequestApproval map[string][]*entity.AttendanceRequestApprovalTable
: Approvals mapped by scan request ID.ScanRequestApprovalRead bool
: Indicates if scan request approvals have been read.StartDate time.Time
: The start date of the cached range.EndDate time.Time
: The end date of the cached range.CompanyID string
: The company ID for which data is cached.
globalLocalScanRequest
Variable
var globalLocalScanRequest = LocalScanRequest{}
A global instance of LocalScanRequest
(singleton pattern).
Functions
NewScanRequestCache(dao *daos.Dao, companyID, calcDate string, read bool) *LocalScanRequest
Creates a new LocalScanRequest
instance.
dao
: The PocketBase DAO.companyID
: The company ID.calcDate
: The calculation date.read
: If true, reads data from the database immediately.
GetGlobalScanRequest() *LocalScanRequest
Returns the global LocalScanRequest
instance.
SetDao(dao *daos.Dao) *LocalScanRequest
Sets the DAO for the instance.