Skip to content

Commit

Permalink
fix(FSADT1-1537): increasing rate limiter (#1213)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
paulushcgcj authored Oct 7, 2024
1 parent bc98c2e commit 5b6b61e
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 13 deletions.
4 changes: 2 additions & 2 deletions backend/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
44 changes: 34 additions & 10 deletions frontend/src/components/DataFetcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>(props.initValue);
const response = ref<any>();
const loading = ref<boolean>();
const lastUpdateRequestTime = ref<number>(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,
});
Expand All @@ -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
}
});
</script>
Expand Down
14 changes: 13 additions & 1 deletion frontend/tests/unittests/components/DataFetcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({}),
Expand Down Expand Up @@ -57,6 +59,7 @@ describe("DataFetcher", () => {
},
});

vi.advanceTimersByTime(305);
await nextTick();

expect(wrapper.html()).toBe("<div>slot content is Loaded</div>");
Expand All @@ -79,6 +82,7 @@ describe("DataFetcher", () => {
},
});

vi.advanceTimersByTime(305);
await nextTick();

// still the same
Expand All @@ -94,6 +98,7 @@ describe("DataFetcher", () => {
url: "/api/data",
minLength: 1,
initValue: { name: "test" },
debounce: 1,
},
slots: {
default: "<div>slot content is {{ content.name }}</div>",
Expand All @@ -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("<div>slot content is Loaded</div>");
expect(wrapper.find("div").text()).toBe("slot content is Loaded");
Expand All @@ -120,6 +127,7 @@ describe("DataFetcher", () => {
minLength: 1,
initValue: { name: "test" },
disabled: true,
debounce: 0,
},
slots: {
default: "<div>slot content is {{ content.name }}</div>",
Expand All @@ -131,6 +139,7 @@ describe("DataFetcher", () => {

await wrapper.setProps({ url: "/api/data/changed" });

vi.advanceTimersByTime(305);
await nextTick();

// still the same
Expand All @@ -147,6 +156,7 @@ describe("DataFetcher", () => {
minLength: 1,
initValue: { name: "test" },
disabled: true,
debounce: 1,
},
slots: {
default: "<div>slot content is {{ content.name }}</div>",
Expand All @@ -161,7 +171,9 @@ describe("DataFetcher", () => {
url: "/api/data/changed",
});

vi.advanceTimersByTime(305);
await nextTick();
await wrapper.vm.$nextTick();

expect(wrapper.html()).toBe("<div>slot content is Loaded</div>");
expect(wrapper.find("div").text()).toBe("slot content is Loaded");
Expand Down
172 changes: 172 additions & 0 deletions legacy/src/test/resources/db/migration/V9__adding_l_to_l.sql
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 5b6b61e

Please sign in to comment.