Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
c599a304
Commit
c599a304
authored
3 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
refactor
parent
6d918f19
No related branches found
Branches containing commit
Tags
12.41.1
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/backend/src/queue/processors/db/export-custom-emojis.ts
+21
-34
21 additions, 34 deletions
...s/backend/src/queue/processors/db/export-custom-emojis.ts
packages/backend/src/queue/processors/db/export-notes.ts
+16
-30
16 additions, 30 deletions
packages/backend/src/queue/processors/db/export-notes.ts
with
37 additions
and
64 deletions
packages/backend/src/queue/processors/db/export-custom-emojis.ts
+
21
−
34
View file @
c599a304
...
...
@@ -39,16 +39,20 @@ export async function exportCustomEmojis(job: Bull.Job, done: () => void): Promi
const
metaStream
=
fs
.
createWriteStream
(
metaPath
,
{
flags
:
'
a
'
});
await
new
Promise
<
void
>
((
res
,
rej
)
=>
{
metaStream
.
write
(
'
[
'
,
err
=>
{
if
(
err
)
{
logger
.
error
(
err
);
rej
(
err
);
}
else
{
res
();
}
const
writeMeta
=
(
text
:
string
):
Promise
<
void
>
=>
{
return
new
Promise
<
void
>
((
res
,
rej
)
=>
{
metaStream
.
write
(
text
,
err
=>
{
if
(
err
)
{
logger
.
error
(
err
);
rej
(
err
);
}
else
{
res
();
}
});
});
});
};
await
writeMeta
(
'
[
'
);
const
customEmojis
=
await
Emojis
.
find
({
where
:
{
...
...
@@ -72,34 +76,17 @@ export async function exportCustomEmojis(job: Bull.Job, done: () => void): Promi
logger
.
error
(
e
);
}
await
new
Promise
<
void
>
((
res
,
rej
)
=>
{
const
content
=
JSON
.
stringify
({
id
:
exportId
,
downloaded
:
downloaded
,
emoji
:
emoji
,
});
const
isFirst
=
customEmojis
.
indexOf
(
emoji
)
===
0
;
metaStream
.
write
(
isFirst
?
content
:
'
,
\n
'
+
content
,
err
=>
{
if
(
err
)
{
logger
.
error
(
err
);
rej
(
err
);
}
else
{
res
();
}
});
const
content
=
JSON
.
stringify
({
id
:
exportId
,
downloaded
:
downloaded
,
emoji
:
emoji
,
});
const
isFirst
=
customEmojis
.
indexOf
(
emoji
)
===
0
;
await
writeMeta
(
isFirst
?
content
:
'
,
\n
'
+
content
);
}
await
new
Promise
<
void
>
((
res
,
rej
)
=>
{
metaStream
.
write
(
'
]
'
,
err
=>
{
if
(
err
)
{
logger
.
error
(
err
);
rej
(
err
);
}
else
{
res
();
}
});
});
await
writeMeta
(
'
]
'
);
metaStream
.
end
();
...
...
This diff is collapsed.
Click to expand it.
packages/backend/src/queue/processors/db/export-notes.ts
+
16
−
30
View file @
c599a304
...
...
@@ -34,16 +34,20 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
const
stream
=
fs
.
createWriteStream
(
path
,
{
flags
:
'
a
'
});
await
new
Promise
<
void
>
((
res
,
rej
)
=>
{
stream
.
write
(
'
[
'
,
err
=>
{
if
(
err
)
{
logger
.
error
(
err
);
rej
(
err
);
}
else
{
res
();
}
const
write
=
(
text
:
string
):
Promise
<
void
>
=>
{
return
new
Promise
<
void
>
((
res
,
rej
)
=>
{
stream
.
write
(
text
,
err
=>
{
if
(
err
)
{
logger
.
error
(
err
);
rej
(
err
);
}
else
{
res
();
}
});
});
});
};
await
write
(
'
[
'
);
let
exportedNotesCount
=
0
;
let
cursor
:
Note
[
'
id
'
]
|
null
=
null
;
...
...
@@ -73,17 +77,8 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
poll
=
await
Polls
.
findOneOrFail
({
noteId
:
note
.
id
});
}
const
content
=
JSON
.
stringify
(
serialize
(
note
,
poll
));
await
new
Promise
<
void
>
((
res
,
rej
)
=>
{
const
isFirst
=
exportedNotesCount
===
0
;
stream
.
write
(
isFirst
?
content
:
'
,
\n
'
+
content
,
err
=>
{
if
(
err
)
{
logger
.
error
(
err
);
rej
(
err
);
}
else
{
res
();
}
});
});
const
isFirst
=
exportedNotesCount
===
0
;
await
write
(
isFirst
?
content
:
'
,
\n
'
+
content
);
exportedNotesCount
++
;
}
...
...
@@ -94,16 +89,7 @@ export async function exportNotes(job: Bull.Job<DbUserJobData>, done: any): Prom
job
.
progress
(
exportedNotesCount
/
total
);
}
await
new
Promise
<
void
>
((
res
,
rej
)
=>
{
stream
.
write
(
'
]
'
,
err
=>
{
if
(
err
)
{
logger
.
error
(
err
);
rej
(
err
);
}
else
{
res
();
}
});
});
await
write
(
'
]
'
);
stream
.
end
();
logger
.
succ
(
`Exported to:
${
path
}
`
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment