Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
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
GitHub Mirror
Renovate Bot
renovate
Commits
57ade2b3
Unverified
Commit
57ade2b3
authored
2 years ago
by
Sergei Zharinov
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor(cache): Restore each revision with own separate method (#17364)
parent
9e2c81f0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/util/cache/repository/impl/base.ts
+33
-14
33 additions, 14 deletions
lib/util/cache/repository/impl/base.ts
with
33 additions
and
14 deletions
lib/util/cache/repository/impl/base.ts
+
33
−
14
View file @
57ade2b3
...
@@ -10,7 +10,14 @@ import {
...
@@ -10,7 +10,14 @@ import {
isValidRev11
,
isValidRev11
,
isValidRev12
,
isValidRev12
,
}
from
'
../common
'
;
}
from
'
../common
'
;
import
type
{
RepoCache
,
RepoCacheData
,
RepoCacheRecord
}
from
'
../types
'
;
import
type
{
RepoCache
,
RepoCacheData
,
RepoCacheRecord
,
RepoCacheRecordV10
,
RepoCacheRecordV11
,
RepoCacheRecordV12
,
}
from
'
../types
'
;
const
compress
=
promisify
(
zlib
.
brotliCompress
);
const
compress
=
promisify
(
zlib
.
brotliCompress
);
const
decompress
=
promisify
(
zlib
.
brotliDecompress
);
const
decompress
=
promisify
(
zlib
.
brotliDecompress
);
...
@@ -26,6 +33,24 @@ export abstract class RepoCacheBase implements RepoCache {
...
@@ -26,6 +33,24 @@ export abstract class RepoCacheBase implements RepoCache {
protected
abstract
write
(
data
:
RepoCacheRecord
):
Promise
<
void
>
;
protected
abstract
write
(
data
:
RepoCacheRecord
):
Promise
<
void
>
;
private
async
restoreFromRev12
(
oldCache
:
RepoCacheRecordV12
):
Promise
<
void
>
{
const
compressed
=
Buffer
.
from
(
oldCache
.
payload
,
'
base64
'
);
const
uncompressed
=
await
decompress
(
compressed
);
const
jsonStr
=
uncompressed
.
toString
(
'
utf8
'
);
this
.
data
=
JSON
.
parse
(
jsonStr
);
this
.
oldHash
=
oldCache
.
hash
;
}
private
restoreFromRev11
(
oldCache
:
RepoCacheRecordV11
):
void
{
this
.
data
=
oldCache
.
data
;
}
private
restoreFromRev10
(
oldCache
:
RepoCacheRecordV10
):
void
{
delete
oldCache
.
repository
;
delete
oldCache
.
revision
;
this
.
data
=
oldCache
;
}
async
load
():
Promise
<
void
>
{
async
load
():
Promise
<
void
>
{
try
{
try
{
const
data
=
await
this
.
read
();
const
data
=
await
this
.
read
();
...
@@ -35,29 +60,23 @@ export abstract class RepoCacheBase implements RepoCache {
...
@@ -35,29 +60,23 @@ export abstract class RepoCacheBase implements RepoCache {
);
);
return
;
return
;
}
}
const
oldCache
=
JSON
.
parse
(
data
);
const
oldCache
=
JSON
.
parse
(
data
)
as
unknown
;
if
(
isValidRev12
(
oldCache
,
this
.
repository
))
{
if
(
isValidRev12
(
oldCache
,
this
.
repository
))
{
const
compressed
=
Buffer
.
from
(
oldCache
.
payload
,
'
base64
'
);
await
this
.
restoreFromRev12
(
oldCache
);
const
uncompressed
=
await
decompress
(
compressed
);
logger
.
debug
(
'
Repository cache is restored from revision 12
'
);
const
jsonStr
=
uncompressed
.
toString
(
'
utf8
'
);
this
.
data
=
JSON
.
parse
(
jsonStr
);
this
.
oldHash
=
oldCache
.
hash
;
logger
.
debug
(
'
Repository cache is valid
'
);
return
;
return
;
}
}
if
(
isValidRev11
(
oldCache
,
this
.
repository
))
{
if
(
isValidRev11
(
oldCache
,
this
.
repository
))
{
this
.
data
=
oldCache
.
data
;
this
.
restoreFromRev11
(
oldCache
)
;
logger
.
debug
(
'
Repository cache is
migrat
ed from
11
revision
'
);
logger
.
debug
(
'
Repository cache is
restor
ed from revision
11
'
);
return
;
return
;
}
}
if
(
isValidRev10
(
oldCache
,
this
.
repository
))
{
if
(
isValidRev10
(
oldCache
,
this
.
repository
))
{
delete
oldCache
.
repository
;
this
.
restoreFromRev10
(
oldCache
);
delete
oldCache
.
revision
;
logger
.
debug
(
'
Repository cache is restored from revision 10
'
);
this
.
data
=
oldCache
;
logger
.
debug
(
'
Repository cache is migrated from 10 revision
'
);
return
;
return
;
}
}
...
...
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