Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
b0d0a76a
authored
Jun 06, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: paging data and image
parent
16018a7e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
7 additions
and
89 deletions
+7
-89
docs/deploy/fastgpt/docker-compose.yml
+1
-1
src/hooks/usePagination.tsx
+1
-1
src/hooks/usePaging.ts
+0
-82
src/service/models/bill.ts
+1
-1
src/service/models/model.ts
+1
-1
src/types/index.d.ts
+3
-3
No files found.
docs/deploy/fastgpt/docker-compose.yml
View file @
b0d0a76a
...
@@ -31,7 +31,7 @@ services:
...
@@ -31,7 +31,7 @@ services:
-
/root/fastgpt/mongo/logs:/var/log/mongodb
-
/root/fastgpt/mongo/logs:/var/log/mongodb
-
/etc/localtime:/etc/localtime:ro
-
/etc/localtime:/etc/localtime:ro
fastgpt
:
fastgpt
:
image
:
ghcr.io/c121914yu/fast
-
gpt:latest
# github
image
:
ghcr.io/c121914yu/fastgpt:latest
# github
# image: c121914yu/fast-gpt:latest # docker hub
# image: c121914yu/fast-gpt:latest # docker hub
# image: registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:latest # 阿里云
# image: registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:latest # 阿里云
network_mode
:
host
network_mode
:
host
...
...
src/hooks/usePagination.tsx
View file @
b0d0a76a
...
@@ -31,7 +31,7 @@ export const usePagination = <T = any,>({
...
@@ -31,7 +31,7 @@ export const usePagination = <T = any,>({
...
params
...
params
});
});
setPageNum
(
num
);
setPageNum
(
num
);
setTotal
(
res
.
total
);
res
.
total
&&
setTotal
(
res
.
total
);
setData
(
res
.
data
);
setData
(
res
.
data
);
}
catch
(
error
:
any
)
{
}
catch
(
error
:
any
)
{
toast
({
toast
({
...
...
src/hooks/usePaging.ts
deleted
100644 → 0
View file @
16018a7e
import
{
useState
,
useCallback
,
useEffect
}
from
'react'
;
import
type
{
PagingData
}
from
'../types/index'
;
import
{
useToast
}
from
'./useToast'
;
export
const
usePaging
=
<
T
=
any
>
({
api
,
pageSize
=
10
,
params
=
{}
}:
{
api
:
(
data
:
any
)
=>
any
;
pageSize
?:
number
;
params
?:
Record
<
string
,
any
>
;
})
=>
{
const
{
toast
}
=
useToast
();
const
[
data
,
setData
]
=
useState
<
T
[]
>
([]);
const
[
pageNum
,
setPageNum
]
=
useState
(
1
);
const
[
total
,
setTotal
]
=
useState
(
0
);
const
[
isLoadAll
,
setIsLoadAll
]
=
useState
(
false
);
const
[
requesting
,
setRequesting
]
=
useState
(
false
);
const
[
initRequesting
,
setInitRequesting
]
=
useState
(
false
);
const
getData
=
useCallback
(
async
(
num
:
number
,
init
=
false
)
=>
{
if
(
requesting
)
return
;
if
(
!
init
&&
isLoadAll
)
return
;
if
(
init
)
{
setInitRequesting
(
true
);
}
setRequesting
(
true
);
try
{
const
res
:
PagingData
<
T
>
=
await
api
({
pageNum
:
num
,
pageSize
,
...
params
});
setData
((
state
)
=>
{
const
data
=
init
?
res
.
data
:
state
.
concat
(
res
.
data
);
if
(
data
.
length
>=
res
.
total
)
{
setIsLoadAll
(
true
);
}
setTotal
(
res
.
total
);
setPageNum
(
num
);
return
data
;
});
}
catch
(
error
:
any
)
{
toast
({
title
:
error
?.
message
||
'获取数据异常'
,
status
:
'error'
});
console
.
log
(
error
);
}
setRequesting
(
false
);
setInitRequesting
(
false
);
return
null
;
},
[
api
,
isLoadAll
,
pageSize
,
params
,
requesting
,
toast
]
);
const
nextPage
=
useCallback
(()
=>
{
if
(
requesting
||
isLoadAll
)
return
;
getData
(
pageNum
+
1
);
},
[
getData
,
isLoadAll
,
pageNum
,
requesting
]);
useEffect
(()
=>
{
getData
(
1
,
true
);
},
[]);
return
{
pageNum
,
pageSize
,
total
,
data
,
getData
,
requesting
,
isLoadAll
,
nextPage
,
initRequesting
,
setData
};
};
src/service/models/bill.ts
View file @
b0d0a76a
...
@@ -47,7 +47,7 @@ try {
...
@@ -47,7 +47,7 @@ try {
BillSchema
.
index
({
time
:
-
1
});
BillSchema
.
index
({
time
:
-
1
});
BillSchema
.
index
({
userId
:
1
});
BillSchema
.
index
({
userId
:
1
});
}
catch
(
error
)
{
}
catch
(
error
)
{
error
;
console
.
log
(
error
)
;
}
}
export
const
Bill
:
Model
<
BillType
>
=
models
[
'bill'
]
||
model
(
'bill'
,
BillSchema
);
export
const
Bill
:
Model
<
BillType
>
=
models
[
'bill'
]
||
model
(
'bill'
,
BillSchema
);
src/service/models/model.ts
View file @
b0d0a76a
...
@@ -86,7 +86,7 @@ try {
...
@@ -86,7 +86,7 @@ try {
ModelSchema
.
index
({
updateTime
:
-
1
});
ModelSchema
.
index
({
updateTime
:
-
1
});
ModelSchema
.
index
({
'share.collection'
:
-
1
});
ModelSchema
.
index
({
'share.collection'
:
-
1
});
}
catch
(
error
)
{
}
catch
(
error
)
{
error
;
console
.
log
(
error
)
;
}
}
export
const
Model
:
MongoModel
<
ModelType
>
=
models
[
'model'
]
||
model
(
'model'
,
ModelSchema
);
export
const
Model
:
MongoModel
<
ModelType
>
=
models
[
'model'
]
||
model
(
'model'
,
ModelSchema
);
src/types/index.d.ts
View file @
b0d0a76a
...
@@ -20,10 +20,10 @@ declare global {
...
@@ -20,10 +20,10 @@ declare global {
}
}
export
type
PagingData
<
T
>
=
{
export
type
PagingData
<
T
>
=
{
pageNum
;
pageNum
:
number
;
pageSize
;
pageSize
:
number
;
data
:
T
[];
data
:
T
[];
total
;
total
?:
number
;
};
};
export
type
RequestPaging
=
{
pageNum
:
number
;
pageSize
:
number
;
[
key
]:
any
};
export
type
RequestPaging
=
{
pageNum
:
number
;
pageSize
:
number
;
[
key
]:
any
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment