Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nicot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
nicot
Commits
d9038368
Commit
d9038368
authored
Dec 21, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add chunk saving
parent
62676f05
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
8 deletions
+28
-8
src/crud-base.ts
src/crud-base.ts
+28
-8
No files found.
src/crud-base.ts
View file @
d9038368
...
@@ -92,13 +92,23 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
...
@@ -92,13 +92,23 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
let
entsToSave
=
ents
;
let
entsToSave
=
ents
;
if
(
entsWithId
.
length
)
{
if
(
entsWithId
.
length
)
{
const
existingEnts
=
await
repo
.
find
({
const
entIds
=
entsWithId
.
map
((
ent
)
=>
ent
.
id
);
const
entIdChunks
=
_
.
chunk
(
entIds
,
65535
);
const
existingEnts
=
(
await
Promise
.
all
(
entIdChunks
.
map
((
chunk
)
=>
repo
.
find
({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-ignore
where
:
{
id
:
In
<
string
|
number
>
(
entsWithId
.
map
((
ent
)
=>
ent
.
id
))
},
where
:
{
id
:
In
<
string
|
number
>
(
chunk
),
},
select
:
[
'
id
'
,
'
deleteTime
'
],
select
:
[
'
id
'
,
'
deleteTime
'
],
withDeleted
:
true
,
withDeleted
:
true
,
});
}),
),
)
).
flat
();
if
(
existingEnts
.
length
)
{
if
(
existingEnts
.
length
)
{
const
existingEntsWithoutDeleteTime
=
existingEnts
.
filter
(
const
existingEntsWithoutDeleteTime
=
existingEnts
.
filter
(
(
ent
)
=>
ent
.
deleteTime
==
null
,
(
ent
)
=>
ent
.
deleteTime
==
null
,
...
@@ -136,7 +146,17 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
...
@@ -136,7 +146,17 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
await
beforeCreate
(
repo
);
await
beforeCreate
(
repo
);
}
}
try
{
try
{
const
results
=
await
repo
.
save
(
entsToSave
as
DeepPartial
<
T
>
[]);
const
entChunksToSave
=
_
.
chunk
(
entsToSave
,
Math
.
floor
(
65535
/
Math
.
max
(
1
,
Object
.
keys
(
entsToSave
[
0
]
||
{}).
length
),
),
);
let
results
:
T
[]
=
[];
for
(
const
entChunk
of
entChunksToSave
)
{
const
savedChunk
=
await
repo
.
save
(
entChunk
);
results
=
results
.
concat
(
savedChunk
);
}
return
{
return
{
results
,
results
,
skipped
,
skipped
,
...
...
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