From 5b6b61e997968c3cacccc16d94fe0aa654e702cb Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Mon, 7 Oct 2024 12:24:18 -0700 Subject: [PATCH] fix(FSADT1-1537): increasing rate limiter (#1213) * fix(FSADT1-1537): increasing rate limiter This is to prevent autocomplete from being blocked due to typing speed * feat(FSADT1-1537): added debounce time to autocomplete * chore: added default value --- backend/openshift.deploy.yml | 4 +- frontend/src/components/DataFetcher.vue | 44 ++++- .../unittests/components/DataFetcher.spec.ts | 14 +- .../db/migration/V9__adding_l_to_l.sql | 172 ++++++++++++++++++ 4 files changed, 221 insertions(+), 13 deletions(-) create mode 100644 legacy/src/test/resources/db/migration/V9__adding_l_to_l.sql diff --git a/backend/openshift.deploy.yml b/backend/openshift.deploy.yml index ddec86ccf3..2dc13e7cde 100644 --- a/backend/openshift.deploy.yml +++ b/backend/openshift.deploy.yml @@ -245,8 +245,8 @@ objects: name: ${NAME}-${ZONE}-${COMPONENT} annotations: haproxy.router.openshift.io/rate-limit-connections: "true" - haproxy.router.openshift.io/rate-limit-connections.rate-http: "50" - haproxy.router.openshift.io/rate-limit-connections.rate-tcp: "25" + haproxy.router.openshift.io/rate-limit-connections.rate-http: "150" + haproxy.router.openshift.io/rate-limit-connections.rate-tcp: "75" spec: host: ${NAME}-${ZONE}-${COMPONENT}.${DOMAIN} port: diff --git a/frontend/src/components/DataFetcher.vue b/frontend/src/components/DataFetcher.vue index 4d47b006b3..6b4d0e4fac 100644 --- a/frontend/src/components/DataFetcher.vue +++ b/frontend/src/components/DataFetcher.vue @@ -3,26 +3,35 @@ import { ref, watch, computed } from "vue"; // Composables import { useFetchTo } from "@/composables/useFetch"; -const props = defineProps<{ +const props = withDefaults(defineProps<{ url: string; params?: object; minLength: number; initValue: object; initFetch?: boolean; disabled?: boolean; -}>(); + debounce?: number; +}>(), + { + minLength: 3, + disabled: false, + debounce: 300, + } +); // Set the initial value to the content const content = ref(props.initValue); const response = ref(); +const loading = ref(); const lastUpdateRequestTime = ref(0); +let debounceTimer: number | null = null; const initialUrlValue = props.url; const searchURL = computed(() => props.url); -const { loading, error, fetch } = useFetchTo(searchURL, response, { +const { loading: fetchLoading, error, fetch } = useFetchTo(searchURL, response, { skip: true, ...props.params, }); @@ -44,18 +53,33 @@ if (!props.disabled && props.initFetch) { }); } + +// Watch for changes in the fetch loading state +// Doing like this now due to the debounce +watch(() => fetchLoading.value, (newVal) => { + loading.value = newVal; +}); + // Watch for changes in the url, and if the difference is greater than the min length, fetch watch([() => props.url, () => props.disabled], () => { if (!props.disabled && calculateStringDifference(initialUrlValue, props.url) >= props.minLength) { + + // added a manual loading state to set the loading state when the user types + loading.value = true; const curRequestTime = Date.now(); - fetch().then(() => { - // Discard the response from old request when a newer one was already responded. - if (curRequestTime >= lastUpdateRequestTime.value) { - content.value = response.value; - lastUpdateRequestTime.value = curRequestTime; - } - }); + if (debounceTimer) { + clearTimeout(debounceTimer); + } + debounceTimer = setTimeout(() => { + fetch().then(() => { + // Discard the response from old request when a newer one was already responded. + if (curRequestTime >= lastUpdateRequestTime.value) { + content.value = response.value; + lastUpdateRequestTime.value = curRequestTime; + } + }); + }, props.debounce); // Debounce time } }); diff --git a/frontend/tests/unittests/components/DataFetcher.spec.ts b/frontend/tests/unittests/components/DataFetcher.spec.ts index 1df4ff38f5..76b1e11cce 100644 --- a/frontend/tests/unittests/components/DataFetcher.spec.ts +++ b/frontend/tests/unittests/components/DataFetcher.spec.ts @@ -5,6 +5,8 @@ import * as fetcher from "@/composables/useFetch"; import DataFetcher from "@/components/DataFetcher.vue"; +vi.useFakeTimers(); + describe("DataFetcher", () => { const mockedFetchTo = (url: string, received: any, config: any = {}) => ({ response: ref({}), @@ -57,6 +59,7 @@ describe("DataFetcher", () => { }, }); + vi.advanceTimersByTime(305); await nextTick(); expect(wrapper.html()).toBe("
slot content is Loaded
"); @@ -79,6 +82,7 @@ describe("DataFetcher", () => { }, }); + vi.advanceTimersByTime(305); await nextTick(); // still the same @@ -94,6 +98,7 @@ describe("DataFetcher", () => { url: "/api/data", minLength: 1, initValue: { name: "test" }, + debounce: 1, }, slots: { default: "
slot content is {{ content.name }}
", @@ -104,8 +109,10 @@ describe("DataFetcher", () => { expect(wrapper.find("div").text()).toBe("slot content is test"); await wrapper.setProps({ url: "/api/data/changed" }); - + + vi.advanceTimersByTime(305); await nextTick(); + await wrapper.vm.$nextTick(); expect(wrapper.html()).toBe("
slot content is Loaded
"); expect(wrapper.find("div").text()).toBe("slot content is Loaded"); @@ -120,6 +127,7 @@ describe("DataFetcher", () => { minLength: 1, initValue: { name: "test" }, disabled: true, + debounce: 0, }, slots: { default: "
slot content is {{ content.name }}
", @@ -131,6 +139,7 @@ describe("DataFetcher", () => { await wrapper.setProps({ url: "/api/data/changed" }); + vi.advanceTimersByTime(305); await nextTick(); // still the same @@ -147,6 +156,7 @@ describe("DataFetcher", () => { minLength: 1, initValue: { name: "test" }, disabled: true, + debounce: 1, }, slots: { default: "
slot content is {{ content.name }}
", @@ -161,7 +171,9 @@ describe("DataFetcher", () => { url: "/api/data/changed", }); + vi.advanceTimersByTime(305); await nextTick(); + await wrapper.vm.$nextTick(); expect(wrapper.html()).toBe("
slot content is Loaded
"); expect(wrapper.find("div").text()).toBe("slot content is Loaded"); diff --git a/legacy/src/test/resources/db/migration/V9__adding_l_to_l.sql b/legacy/src/test/resources/db/migration/V9__adding_l_to_l.sql new file mode 100644 index 0000000000..d5aa8e3422 --- /dev/null +++ b/legacy/src/test/resources/db/migration/V9__adding_l_to_l.sql @@ -0,0 +1,172 @@ +-- Create a new entry in the REGISTRY_COMPANY_TYPE_CODE table for the BCeID FM type in an idempotent way +MERGE INTO THE.REGISTRY_COMPANY_TYPE_CODE tgt +USING ( + SELECT 'LP' AS REGISTRY_COMPANY_TYPE_CODE, + 'Limited Partnership' AS DESCRIPTION, + TIMESTAMP '2024-10-07 00:00:00.0' AS EFFECTIVE_DATE, + TIMESTAMP '9999-12-31 00:00:00.0' AS EXPIRY_DATE, + TIMESTAMP '2024-10-07 00:00:00.0' AS UPDATE_TIMESTAMP + FROM DUAL +) src +ON (tgt.REGISTRY_COMPANY_TYPE_CODE = src.REGISTRY_COMPANY_TYPE_CODE) +WHEN MATCHED THEN + UPDATE SET + tgt.DESCRIPTION = src.DESCRIPTION, + tgt.EFFECTIVE_DATE = src.EFFECTIVE_DATE, + tgt.EXPIRY_DATE = src.EXPIRY_DATE, + tgt.UPDATE_TIMESTAMP = src.UPDATE_TIMESTAMP +WHEN NOT MATCHED THEN + INSERT (REGISTRY_COMPANY_TYPE_CODE, DESCRIPTION, EFFECTIVE_DATE, EXPIRY_DATE, UPDATE_TIMESTAMP) + VALUES (src.REGISTRY_COMPANY_TYPE_CODE, src.DESCRIPTION, src.EFFECTIVE_DATE, src.EXPIRY_DATE, src.UPDATE_TIMESTAMP); + +-- Create a new entry in the CLIENT_TYPE_COMPANY_XREF table for the BCeID FM code linking with I in an idempotent way +MERGE INTO THE.CLIENT_TYPE_COMPANY_XREF tgt +USING ( + SELECT 'L' AS CLIENT_TYPE_CODE, + 'LP' AS REGISTRY_COMPANY_TYPE_CODE, + 'CLIADMIN' AS ADD_USERID, + TIMESTAMP '2024-10-07 00:00:00.0' AS ADD_TIMESTAMP, + 'CLIADMIN' AS UPDATE_USERID, + TIMESTAMP '2024-10-07 00:00:00.0' AS UPDATE_TIMESTAMP + FROM DUAL +) src +ON (tgt.CLIENT_TYPE_CODE = src.CLIENT_TYPE_CODE AND tgt.REGISTRY_COMPANY_TYPE_CODE = src.REGISTRY_COMPANY_TYPE_CODE) +WHEN MATCHED THEN + UPDATE SET + tgt.ADD_USERID = src.ADD_USERID, + tgt.ADD_TIMESTAMP = src.ADD_TIMESTAMP, + tgt.UPDATE_USERID = src.UPDATE_USERID, + tgt.UPDATE_TIMESTAMP = src.UPDATE_TIMESTAMP +WHEN NOT MATCHED THEN + INSERT (CLIENT_TYPE_CODE, REGISTRY_COMPANY_TYPE_CODE, ADD_USERID, ADD_TIMESTAMP, UPDATE_USERID, UPDATE_TIMESTAMP) + VALUES (src.CLIENT_TYPE_CODE, src.REGISTRY_COMPANY_TYPE_CODE, src.ADD_USERID, src.ADD_TIMESTAMP, src.UPDATE_USERID, src.UPDATE_TIMESTAMP); + +-- Create a new entry in the REGISTRY_COMPANY_TYPE_CODE table for the BCeID FM type in an idempotent way +MERGE INTO THE.REGISTRY_COMPANY_TYPE_CODE tgt +USING ( + SELECT 'LL' AS REGISTRY_COMPANY_TYPE_CODE, + 'Limited Liability Partnership' AS DESCRIPTION, + TIMESTAMP '2024-10-07 00:00:00.0' AS EFFECTIVE_DATE, + TIMESTAMP '9999-12-31 00:00:00.0' AS EXPIRY_DATE, + TIMESTAMP '2024-10-07 00:00:00.0' AS UPDATE_TIMESTAMP + FROM DUAL +) src +ON (tgt.REGISTRY_COMPANY_TYPE_CODE = src.REGISTRY_COMPANY_TYPE_CODE) +WHEN MATCHED THEN + UPDATE SET + tgt.DESCRIPTION = src.DESCRIPTION, + tgt.EFFECTIVE_DATE = src.EFFECTIVE_DATE, + tgt.EXPIRY_DATE = src.EXPIRY_DATE, + tgt.UPDATE_TIMESTAMP = src.UPDATE_TIMESTAMP +WHEN NOT MATCHED THEN + INSERT (REGISTRY_COMPANY_TYPE_CODE, DESCRIPTION, EFFECTIVE_DATE, EXPIRY_DATE, UPDATE_TIMESTAMP) + VALUES (src.REGISTRY_COMPANY_TYPE_CODE, src.DESCRIPTION, src.EFFECTIVE_DATE, src.EXPIRY_DATE, src.UPDATE_TIMESTAMP); + +-- Create a new entry in the CLIENT_TYPE_COMPANY_XREF table for the BCeID FM code linking with I in an idempotent way +MERGE INTO THE.CLIENT_TYPE_COMPANY_XREF tgt +USING ( + SELECT 'L' AS CLIENT_TYPE_CODE, + 'LL' AS REGISTRY_COMPANY_TYPE_CODE, + 'CLIADMIN' AS ADD_USERID, + TIMESTAMP '2024-10-07 00:00:00.0' AS ADD_TIMESTAMP, + 'CLIADMIN' AS UPDATE_USERID, + TIMESTAMP '2024-10-07 00:00:00.0' AS UPDATE_TIMESTAMP + FROM DUAL +) src +ON (tgt.CLIENT_TYPE_CODE = src.CLIENT_TYPE_CODE AND tgt.REGISTRY_COMPANY_TYPE_CODE = src.REGISTRY_COMPANY_TYPE_CODE) +WHEN MATCHED THEN + UPDATE SET + tgt.ADD_USERID = src.ADD_USERID, + tgt.ADD_TIMESTAMP = src.ADD_TIMESTAMP, + tgt.UPDATE_USERID = src.UPDATE_USERID, + tgt.UPDATE_TIMESTAMP = src.UPDATE_TIMESTAMP +WHEN NOT MATCHED THEN + INSERT (CLIENT_TYPE_CODE, REGISTRY_COMPANY_TYPE_CODE, ADD_USERID, ADD_TIMESTAMP, UPDATE_USERID, UPDATE_TIMESTAMP) + VALUES (src.CLIENT_TYPE_CODE, src.REGISTRY_COMPANY_TYPE_CODE, src.ADD_USERID, src.ADD_TIMESTAMP, src.UPDATE_USERID, src.UPDATE_TIMESTAMP); + +-- Create a new entry in the REGISTRY_COMPANY_TYPE_CODE table for the BCeID FM type in an idempotent way +MERGE INTO THE.REGISTRY_COMPANY_TYPE_CODE tgt +USING ( + SELECT 'XP' AS REGISTRY_COMPANY_TYPE_CODE, + 'Extraprovincial Limited Partnership' AS DESCRIPTION, + TIMESTAMP '2024-10-07 00:00:00.0' AS EFFECTIVE_DATE, + TIMESTAMP '9999-12-31 00:00:00.0' AS EXPIRY_DATE, + TIMESTAMP '2024-10-07 00:00:00.0' AS UPDATE_TIMESTAMP + FROM DUAL +) src +ON (tgt.REGISTRY_COMPANY_TYPE_CODE = src.REGISTRY_COMPANY_TYPE_CODE) +WHEN MATCHED THEN + UPDATE SET + tgt.DESCRIPTION = src.DESCRIPTION, + tgt.EFFECTIVE_DATE = src.EFFECTIVE_DATE, + tgt.EXPIRY_DATE = src.EXPIRY_DATE, + tgt.UPDATE_TIMESTAMP = src.UPDATE_TIMESTAMP +WHEN NOT MATCHED THEN + INSERT (REGISTRY_COMPANY_TYPE_CODE, DESCRIPTION, EFFECTIVE_DATE, EXPIRY_DATE, UPDATE_TIMESTAMP) + VALUES (src.REGISTRY_COMPANY_TYPE_CODE, src.DESCRIPTION, src.EFFECTIVE_DATE, src.EXPIRY_DATE, src.UPDATE_TIMESTAMP); + +-- Create a new entry in the CLIENT_TYPE_COMPANY_XREF table for the BCeID FM code linking with I in an idempotent way +MERGE INTO THE.CLIENT_TYPE_COMPANY_XREF tgt +USING ( + SELECT 'L' AS CLIENT_TYPE_CODE, + 'XP' AS REGISTRY_COMPANY_TYPE_CODE, + 'CLIADMIN' AS ADD_USERID, + TIMESTAMP '2024-10-07 00:00:00.0' AS ADD_TIMESTAMP, + 'CLIADMIN' AS UPDATE_USERID, + TIMESTAMP '2024-10-07 00:00:00.0' AS UPDATE_TIMESTAMP + FROM DUAL +) src +ON (tgt.CLIENT_TYPE_CODE = src.CLIENT_TYPE_CODE AND tgt.REGISTRY_COMPANY_TYPE_CODE = src.REGISTRY_COMPANY_TYPE_CODE) +WHEN MATCHED THEN + UPDATE SET + tgt.ADD_USERID = src.ADD_USERID, + tgt.ADD_TIMESTAMP = src.ADD_TIMESTAMP, + tgt.UPDATE_USERID = src.UPDATE_USERID, + tgt.UPDATE_TIMESTAMP = src.UPDATE_TIMESTAMP +WHEN NOT MATCHED THEN + INSERT (CLIENT_TYPE_CODE, REGISTRY_COMPANY_TYPE_CODE, ADD_USERID, ADD_TIMESTAMP, UPDATE_USERID, UPDATE_TIMESTAMP) + VALUES (src.CLIENT_TYPE_CODE, src.REGISTRY_COMPANY_TYPE_CODE, src.ADD_USERID, src.ADD_TIMESTAMP, src.UPDATE_USERID, src.UPDATE_TIMESTAMP); + +-- Create a new entry in the REGISTRY_COMPANY_TYPE_CODE table for the BCeID FM type in an idempotent way +MERGE INTO THE.REGISTRY_COMPANY_TYPE_CODE tgt +USING ( + SELECT 'XL' AS REGISTRY_COMPANY_TYPE_CODE, + 'Extraprovincial Limited Liability Partnership' AS DESCRIPTION, + TIMESTAMP '2024-10-07 00:00:00.0' AS EFFECTIVE_DATE, + TIMESTAMP '9999-12-31 00:00:00.0' AS EXPIRY_DATE, + TIMESTAMP '2024-10-07 00:00:00.0' AS UPDATE_TIMESTAMP + FROM DUAL +) src +ON (tgt.REGISTRY_COMPANY_TYPE_CODE = src.REGISTRY_COMPANY_TYPE_CODE) +WHEN MATCHED THEN + UPDATE SET + tgt.DESCRIPTION = src.DESCRIPTION, + tgt.EFFECTIVE_DATE = src.EFFECTIVE_DATE, + tgt.EXPIRY_DATE = src.EXPIRY_DATE, + tgt.UPDATE_TIMESTAMP = src.UPDATE_TIMESTAMP +WHEN NOT MATCHED THEN + INSERT (REGISTRY_COMPANY_TYPE_CODE, DESCRIPTION, EFFECTIVE_DATE, EXPIRY_DATE, UPDATE_TIMESTAMP) + VALUES (src.REGISTRY_COMPANY_TYPE_CODE, src.DESCRIPTION, src.EFFECTIVE_DATE, src.EXPIRY_DATE, src.UPDATE_TIMESTAMP); + +-- Create a new entry in the CLIENT_TYPE_COMPANY_XREF table for the BCeID FM code linking with I in an idempotent way +MERGE INTO THE.CLIENT_TYPE_COMPANY_XREF tgt +USING ( + SELECT 'L' AS CLIENT_TYPE_CODE, + 'XL' AS REGISTRY_COMPANY_TYPE_CODE, + 'CLIADMIN' AS ADD_USERID, + TIMESTAMP '2024-10-07 00:00:00.0' AS ADD_TIMESTAMP, + 'CLIADMIN' AS UPDATE_USERID, + TIMESTAMP '2024-10-07 00:00:00.0' AS UPDATE_TIMESTAMP + FROM DUAL +) src +ON (tgt.CLIENT_TYPE_CODE = src.CLIENT_TYPE_CODE AND tgt.REGISTRY_COMPANY_TYPE_CODE = src.REGISTRY_COMPANY_TYPE_CODE) +WHEN MATCHED THEN + UPDATE SET + tgt.ADD_USERID = src.ADD_USERID, + tgt.ADD_TIMESTAMP = src.ADD_TIMESTAMP, + tgt.UPDATE_USERID = src.UPDATE_USERID, + tgt.UPDATE_TIMESTAMP = src.UPDATE_TIMESTAMP +WHEN NOT MATCHED THEN + INSERT (CLIENT_TYPE_CODE, REGISTRY_COMPANY_TYPE_CODE, ADD_USERID, ADD_TIMESTAMP, UPDATE_USERID, UPDATE_TIMESTAMP) + VALUES (src.CLIENT_TYPE_CODE, src.REGISTRY_COMPANY_TYPE_CODE, src.ADD_USERID, src.ADD_TIMESTAMP, src.UPDATE_USERID, src.UPDATE_TIMESTAMP); +