Map caching in Redis
This commit is contained in:
@ -1,12 +1,16 @@
|
||||
import useSWR from "swr";
|
||||
import useSWR, { SWRConfiguration } from "swr";
|
||||
import RoleService from "../services/RoleService";
|
||||
import UserService from "../services/UserService";
|
||||
import { fetcher } from "../http/axiosInstance";
|
||||
import { fileTypeFromBlob } from "file-type/core";
|
||||
import { BASE_URL } from "../constants";
|
||||
|
||||
const swrOptions: SWRConfiguration = {
|
||||
revalidateOnFocus: false,
|
||||
}
|
||||
|
||||
export function useRoles() {
|
||||
const { data, error, isLoading } = useSWR(`/auth/roles`, RoleService.getRoles)
|
||||
const { data, error, isLoading } = useSWR(`/auth/roles`, RoleService.getRoles, swrOptions)
|
||||
|
||||
return {
|
||||
roles: data?.data,
|
||||
@ -16,7 +20,7 @@ export function useRoles() {
|
||||
}
|
||||
|
||||
export function useUsers() {
|
||||
const { data, error, isLoading } = useSWR(`/auth/user`, UserService.getUsers)
|
||||
const { data, error, isLoading } = useSWR(`/auth/user`, UserService.getUsers, swrOptions)
|
||||
|
||||
return {
|
||||
users: data?.data,
|
||||
@ -26,7 +30,7 @@ export function useUsers() {
|
||||
}
|
||||
|
||||
export function useCompanies(limit?: number, offset?: number) {
|
||||
const { data, error, isLoading } = useSWR(`/info/companies?limit=${limit || 10}&offset=${offset || 0}`, fetcher)
|
||||
const { data, error, isLoading } = useSWR(`/info/companies?limit=${limit || 10}&offset=${offset || 0}`, fetcher, swrOptions)
|
||||
|
||||
return {
|
||||
companies: data,
|
||||
@ -39,9 +43,7 @@ export function useFolders(limit?: number, offset?: number) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
`/info/document_folder?limit=${limit || 10}&offset=${offset || 0}`,
|
||||
fetcher,
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -55,9 +57,7 @@ export function useDocuments(folder_id?: number) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
folder_id ? `/info/documents/${folder_id}` : null,
|
||||
fetcher,
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -71,9 +71,7 @@ export function useDownload(folder_id?: number | null, id?: number | null) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
folder_id && id ? `/info/document/${folder_id}&${id}` : null,
|
||||
folder_id && id ? (url) => fetcher(url, BASE_URL.info, "blob") : null,
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -87,9 +85,7 @@ export function useFileType(fileName?: string | null, file?: Blob | null) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
fileName && file ? `/filetype/${fileName}` : null,
|
||||
file ? () => fileTypeFromBlob(file) : null,
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -103,9 +99,7 @@ export function useReport(city_id?: number | null) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
city_id ? `/info/reports/${city_id}?to_export=false` : null,
|
||||
(url) => fetcher(url, BASE_URL.info),
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -119,9 +113,7 @@ export function useReportExport(city_id?: number | null, to_export?: boolean) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
city_id && to_export ? `/info/reports/${city_id}?to_export=${to_export}` : null,
|
||||
(url) => fetcher(url, BASE_URL.info, 'blob'),
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -138,9 +130,7 @@ export function useAddress(limit?: number, page?: number) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
`/general/address?limit=${limit || 10}&page=${page || 1}`,
|
||||
(url) => fetcher(url, BASE_URL.fuel),
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -154,9 +144,7 @@ export function useRegions(limit?: number, page?: number, search?: string | null
|
||||
const { data, error, isLoading } = useSWR(
|
||||
`/general/regions?limit=${limit || 10}&page=${page || 1}${search ? `&search=${search}` : ''}`,
|
||||
(url) => fetcher(url, BASE_URL.fuel),
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -170,9 +158,7 @@ export function useCities(limit?: number, page?: number, search?: string | null)
|
||||
const { data, error, isLoading } = useSWR(
|
||||
`/general/cities?limit=${limit || 10}&page=${page || 1}${search ? `&search=${search}` : ''}`,
|
||||
(url) => fetcher(url, BASE_URL.fuel),
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -186,9 +172,7 @@ export function useBoilers(limit?: number, page?: number, search?: string) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
`/general/boilers?limit=${limit || 10}&page=${page || 1}${search ? `&search=${search}` : ''}`,
|
||||
(url) => fetcher(url, BASE_URL.fuel),
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -204,9 +188,7 @@ export function useServers(region_id?: number | null, offset?: number, limit?: n
|
||||
const { data, error, isLoading } = useSWR(
|
||||
region_id ? `/api/servers?region_id=${region_id}&offset=${offset || 0}&limit=${limit || 10}` : `/api/servers?offset=${offset || 0}&limit=${limit || 10}`,
|
||||
(url: string) => fetcher(url, BASE_URL.servers),
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -220,9 +202,7 @@ export function useServersInfo(region_id?: number, offset?: number, limit?: numb
|
||||
const { data, error, isLoading } = useSWR(
|
||||
region_id ? `/api/servers_info?region_id=${region_id}&offset=${offset || 0}&limit=${limit || 10}` : `/api/servers_info?offset=${offset || 0}&limit=${limit || 10}`,
|
||||
(url: string) => fetcher(url, BASE_URL.servers),
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -236,9 +216,7 @@ export function useServer(server_id?: number) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
server_id ? `/api/server/${server_id}` : null,
|
||||
(url) => fetcher(url, BASE_URL.servers),
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -252,9 +230,7 @@ export function useServerIps(server_id?: number | null, offset?: number, limit?:
|
||||
const { data, error, isLoading } = useSWR(
|
||||
server_id ? `/api/server_ips?server_id=${server_id}&offset=${offset || 0}&limit=${limit || 10}` : `/api/server_ips?offset=${offset || 0}&limit=${limit || 10}`,
|
||||
(url: string) => fetcher(url, BASE_URL.servers),
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -270,9 +246,7 @@ export function useHardwares(server_id?: number, offset?: number, limit?: number
|
||||
const { data, error, isLoading } = useSWR(
|
||||
server_id ? `/api/hardwares?server_id=${server_id}&offset=${offset || 0}&limit=${limit || 10}` : `/api/hardwares?offset=${offset || 0}&limit=${limit || 10}`,
|
||||
(url: string) => fetcher(url, BASE_URL.servers),
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -287,9 +261,7 @@ export function useHardware(hardware_id?: number) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
hardware_id ? `/api/hardware/${hardware_id}` : null,
|
||||
(url) => fetcher(url, BASE_URL.servers),
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -305,9 +277,7 @@ export function useStorages(hardware_id?: number, offset?: number, limit?: numbe
|
||||
const { data, error, isLoading } = useSWR(
|
||||
hardware_id ? `/api/storages?hardware_id=${hardware_id}&offset=${offset || 0}&limit=${limit || 10}` : `/api/storages?offset=${offset || 0}&limit=${limit || 10}`,
|
||||
(url: string) => fetcher(url, BASE_URL.servers),
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
@ -321,9 +291,7 @@ export function useStorage(storage_id?: number) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
storage_id ? `/api/storage/${storage_id}` : null,
|
||||
(url) => fetcher(url, BASE_URL.servers),
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
swrOptions
|
||||
)
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user