Skip to content

Commit

Permalink
Merge pull request #1851 from bcgov/fix/edx-2098
Browse files Browse the repository at this point in the history
Refactor data cacheing
  • Loading branch information
arcshiftsolutions authored Jan 18, 2024
2 parents 22c660f + b484e1d commit 8fdb7e2
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 55 deletions.
26 changes: 13 additions & 13 deletions backend/src/routes/cache-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ const constants = require('../util/constants');

const extendSession = utils.extendSession();

router.get('/district/:districtId', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedDistrictByDistrictId);
router.get('/district/:districtId', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedDistrictByDistrictId);

router.get('/district', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedDistricts);
router.get('/district', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedDistricts);

router.get('/school', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedSchools);
router.get('/school', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedSchools);

router.get('/school/:id', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedSchoolBySchoolID);
router.get('/school/:id', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedSchoolBySchoolID);

router.get('/authority', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedAuthorities);
router.get('/authority', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedAuthorities);

router.get('/authority/:id', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedAuthorityByAuthorityID);
router.get('/authority/:id', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedAuthorityByAuthorityID);

router.get('/school-category-facility-type', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedSchoolCategoryFacilityTypes);
router.get('/school-category-facility-type', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedSchoolCategoryFacilityTypes);

router.get('/facility-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedInstituteData(constants.CACHE_KEYS.FACILITY_TYPES,'server:institute:facilityTypeURL'));
router.get('/facility-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.FACILITY_TYPES,'server:institute:facilityTypeURL'));

router.get('/district-contact-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedInstituteData(constants.CACHE_KEYS.DISTRICT_CONTACT_TYPE_CODES,'server:institute:facilityTypeURL'));
router.get('/district-contact-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.DISTRICT_CONTACT_TYPE_CODES,'server:institute:facilityTypeURL'));

router.get('/facility-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedInstituteData(constants.CACHE_KEYS.FACILITY_TYPES,'server:institute:facilityTypeURL'));
router.get('/facility-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.FACILITY_TYPES,'server:institute:facilityTypeURL'));

router.get('/school-category-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_CATEGORY_TYPES,'server:institute:categoryCodesURL'));
router.get('/school-category-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_CATEGORY_TYPES,'server:institute:categoryCodesURL'));

router.get('/school-organization-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession,getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_ORGANIZATION_TYPES,'server:institute:organizationCodeURL'));
router.get('/school-organization-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_ORGANIZATION_TYPES,'server:institute:organizationCodeURL'));

router.get('/school-neighborhood-learning-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_NEIGHBOURHOOD_LEARNING_TYPES,'server:institute:neighbourhoodLearningURL'));
router.get('/school-neighborhood-learning-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_NEIGHBOURHOOD_LEARNING_TYPES,'server:institute:neighbourhoodLearningURL'));

router.get('/authority-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.AUTHORITY_TYPES,'server:institute:authorityTypeCodesURL'));

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export default {
}
},
async beforeMount() {
await appStore().getCodes();
await appStore().getInstituteCodes();
},
mounted() {
if (this.VIEW_EDIT_PEN_REQUEST_BATCH_FILES_ROLE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default {
...mapState(appStore, ['collectionTypeCodesMap']),
},
async created() {
await appStore().getCodes().then(() => {
await appStore().getSdcCodes().then(() => {
this.collectionTypesMap = this.collectionTypeCodesMap;
this.collectionTypesMap.forEach((type) => {
this.collectionTypes.push(type['label']);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/institute/common/SchoolFunding.vue
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export default {
},
mounted() {
instituteStore().getAllGradeCodes();
appStore().getCodes().then(() => {
appStore().getSdcCodes().then(() => {
this.schoolFundingGroups = this.activeFundingGroups;
this.getHistoricalCollectionsForSchool();
this.loadSchoolsFundingData();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/institute/common/SchoolHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default {
},
},
async beforeMount() {
await appStore().getCodes();
await appStore().getInstituteCodes();
},
mounted() {
this.getSchoolHistory();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/institute/common/SchoolMove.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default {
},
},
created() {
appStore().getCodes().then(() => this.getSchoolDetails());
appStore().getInstituteCodes().then(() => this.getSchoolDetails());
},
methods: {
hasRequiredPermission,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ export default {
if (!this.gradeCodeObjects || !this.genders) {
await studentStore().getCodes();
}
await appStore().getCodes();
await appStore().getInstituteCodes();
},
computed: {
...mapState(nominalRollStudentSearchStore, ['nomRollStudentSearchResponse', 'nomRollStudentSearchCriteria', 'currentNomRollStudentSearchParams']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export default {
};
},
async beforeMount() {
await appStore().getCodes();
await appStore().getInstituteCodes();
},
computed: {
...mapState(penRequestBatchStudentSearchStore, ['prbStudentSearchResponse', 'prbStudentSearchCriteria', 'currentPrbStudentSearchParams']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default {
};
},
created() {
appStore().getCodes();
appStore().getInstituteCodes();
},
mounted() {
this.loadPenCoords();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export default {
};
},
async beforeMount() {
await appStore().getCodes();
await appStore().getInstituteCodes();
},
computed: {
...mapState(studentStore, ['demogCodeObjects', 'statusCodeObjects', 'gradeCodeObjects','documentTypeCodes']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export default {
await edxStore().getSchoolExchangeRoles();
}
if (this.schoolMap.size === 0) {
await appStore().getCodes();
await appStore().getInstituteCodes();
}
},
created() {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/secure-message/ExchangePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ export default {
}
},
created() {
appStore().getCodes();
appStore().getInstituteCodes();
edxStore().getCodes();
edxStore().getMinistryTeams().then(() => {
this.getExchanges();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/mixins/getSecureExchangeContactMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {appStore} from '@/store/modules/app';

export default {
mounted() {
appStore().getCodes();
appStore().getInstituteCodes();
edxStore().getCodes();
},
computed: {
Expand Down
49 changes: 19 additions & 30 deletions frontend/src/store/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,36 +119,25 @@ export const appStore = defineStore('app', {
this.collectionTypeCodesMap.set(element.collectionTypeCode, element)
})
},
async getCodes() {
if(localStorage.getItem('jwtToken')) { // DONT Call api if there is not token.
if(this.mincodeSchoolNames.size === 0) {
const response = await ApiService.getAllSchools();
await this.setMincodeSchoolNameAndDistrictCodes(response.data);
}
if (this.activeSchools.length === 0) {
const response = await ApiService.getActiveSchools();
await this.setActiveSchools(response.data);
}
if(this.districtMap.size === 0) {
const response = await ApiService.getDistricts();
await this.setDistricts(response.data);
}
if (this.activeDistricts.length === 0) {
const response = await ApiService.getActiveDistricts();
await this.setActiveDistricts(response.data);
}
if(this.independentAuthorityMap.size === 0) {
const response = await ApiService.getAuthorities();
await this.setIndependentAuthorities(response.data);
}
if(this.fundingGroupsMap.size === 0 && !this.config.DISABLE_SDC_FUNCTIONALITY) {
const response = await ApiService.getAllFundingGroups();
await this.setFundingGroups(response.data);
}
if(this.collectionTypeCodesMap.size === 0 && !this.config.DISABLE_SDC_FUNCTIONALITY) {
const response = await ApiService.getAllCollectionTypeCodes();
await this.setCollectionTypeCodes(response.data);
}
async getInstituteCodes() {
if(localStorage.getItem('jwtToken')) {// DONT Call api if there is not token.
const promises = [
... this.mincodeSchoolNames.size === 0 ? [ApiService.getAllSchools().then((res) => this.setMincodeSchoolNameAndDistrictCodes(res.data))] : [],
... this.activeSchools.length === 0 ? [ApiService.getActiveSchools().then((res) => this.setActiveSchools(res.data))] : [],
... this.districtMap.size === 0 ? [ApiService.getDistricts().then((res) => this.setDistricts(res.data))] : [],
... this.activeDistricts.length === 0 ? [ApiService.getActiveDistricts().then((res) => this.setActiveDistricts(res.data))] : [],
... this.independentAuthorityMap.size === 0 ? [ApiService.getAuthorities().then((res) => this.setIndependentAuthorities(res.data))] : []
]
return Promise.all(promises)
}
},
async getSdcCodes(){
if(localStorage.getItem('jwtToken')){
const promises = [
... this.fundingGroupsMap.size === 0 ? [ApiService.getAllFundingGroups().then((res)=> this.setFundingGroups(res.data))] : [],
... this.collectionTypeCodesMap.size === 0 ? [ApiService.getAllCollectionTypeCodes().then((res) => this.setCollectionTypeCodes(res.data))]: []
];
return Promise.all(promises)
}
},
async getConfig() {
Expand Down

0 comments on commit 8fdb7e2

Please sign in to comment.