Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
4b3de36a
Commit
4b3de36a
authored
Aug 26, 2021
by
Mark Florian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Seed history if it doesn't exist
parent
3a7a35fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
21 deletions
+72
-21
config/helpers/incremental_webpack_compiler/history.js
config/helpers/incremental_webpack_compiler/history.js
+72
-21
No files found.
config/helpers/incremental_webpack_compiler/history.js
View file @
4b3de36a
...
...
@@ -3,6 +3,41 @@
const
fs
=
require
(
'
fs
'
);
const
log
=
require
(
'
./log
'
);
const
ESSENTIAL_ENTRY_POINTS
=
[
// Login page
'
pages.sessions.new
'
,
// Explore page
'
pages.root
'
,
];
// TODO: Find a way to keep this list up-to-date/relevant.
const
COMMON_ENTRY_POINTS
=
[
...
ESSENTIAL_ENTRY_POINTS
,
'
pages.admin
'
,
'
pages.admin.dashboard
'
,
'
pages.dashboard.groups.index
'
,
'
pages.dashboard.projects.index
'
,
'
pages.groups.new
'
,
'
pages.groups.show
'
,
'
pages.profiles.preferences.show
'
,
'
pages.projects.commit.show
'
,
'
pages.projects.edit
'
,
'
pages.projects.issues.index
'
,
'
pages.projects.issues.new
'
,
'
pages.projects.issues.show
'
,
'
pages.projects.jobs.show
'
,
'
pages.projects.merge_requests.index
'
,
'
pages.projects.merge_requests.show
'
,
'
pages.projects.milestones.index
'
,
'
pages.projects.new
'
,
'
pages.projects.pipelines.index
'
,
'
pages.projects.pipelines.show
'
,
'
pages.projects.settings.ci_cd.show
'
,
'
pages.projects.settings.repository.show
'
,
'
pages.projects.show
'
,
'
pages.users
'
,
];
/**
* The History class is responsible for tracking which entry points have been
* requested, and persisting/loading the history to/from disk.
...
...
@@ -10,18 +45,15 @@ const log = require('./log');
class
History
{
constructor
(
historyFilePath
)
{
this
.
_historyFilePath
=
historyFilePath
;
this
.
_history
=
this
.
_loadHistoryFile
();
this
.
_history
=
{};
this
.
_loadHistoryFile
();
}
onRequestEntryPoint
(
entryPoint
)
{
const
wasVisitedRecently
=
this
.
isRecentlyVisited
(
entryPoint
);
if
(
!
this
.
_history
[
entryPoint
])
{
this
.
_history
[
entryPoint
]
=
{
lastVisit
:
null
,
count
:
0
};
}
this
.
_history
[
entryPoint
].
lastVisit
=
Date
.
now
();
this
.
_history
[
entryPoint
].
count
+=
1
;
this
.
_addEntryPoint
(
entryPoint
);
this
.
_writeHistoryFile
();
...
...
@@ -40,26 +72,51 @@ class History {
// Private methods
_addEntryPoint
(
entryPoint
)
{
if
(
!
this
.
_history
[
entryPoint
])
{
this
.
_history
[
entryPoint
]
=
{
lastVisit
:
null
,
count
:
0
};
}
this
.
_history
[
entryPoint
].
lastVisit
=
Date
.
now
();
this
.
_history
[
entryPoint
].
count
+=
1
;
}
_writeHistoryFile
()
{
try
{
fs
.
writeFileSync
(
this
.
_historyFilePath
,
JSON
.
stringify
(
this
.
_history
),
'
utf8
'
);
}
catch
(
e
)
{
log
(
'
Warning – Could not write to history
'
,
e
.
message
);
}
catch
(
e
rror
)
{
log
(
'
Warning – Could not write to history
'
,
e
rror
.
message
);
}
}
_loadHistoryFile
()
{
let
history
=
{};
try
{
fs
.
accessSync
(
this
.
_historyFilePath
);
}
catch
(
e
)
{
// History file doesn't exist; attempt to seed it, and return early
this
.
_seedHistory
();
return
;
}
// History file already exists; attempt to load its contents into memory
try
{
history
=
JSON
.
parse
(
fs
.
readFileSync
(
this
.
_historyFilePath
,
'
utf8
'
));
const
historySize
=
Object
.
keys
(
history
).
length
;
this
.
_
history
=
JSON
.
parse
(
fs
.
readFileSync
(
this
.
_historyFilePath
,
'
utf8
'
));
const
historySize
=
Object
.
keys
(
this
.
_
history
).
length
;
log
(
`Successfully loaded history containing
${
historySize
}
entry points`
);
}
catch
(
error
)
{
log
(
`Could not load history:
${
error
}
`
);
log
(
'
Could not load history
'
,
error
.
message
);
}
}
return
history
;
/**
* Seeds a reasonable set of approximately the most common entry points to
* seed the history. This helps to avoid fresh GDK installs showing the
* compiling overlay too often.
*/
_seedHistory
()
{
log
(
'
Seeding history...
'
);
COMMON_ENTRY_POINTS
.
forEach
((
entryPoint
)
=>
this
.
_addEntryPoint
(
entryPoint
));
this
.
_writeHistoryFile
();
}
}
...
...
@@ -109,13 +166,7 @@ class HistoryWithTTL extends History {
[],
);
this
.
_recentEntryPoints
=
new
Set
([
// Login page
'
pages.sessions.new
'
,
// Explore page
'
pages.root
'
,
...
recentEntryPoints
,
]);
this
.
_recentEntryPoints
=
new
Set
([...
ESSENTIAL_ENTRY_POINTS
,
...
recentEntryPoints
]);
}
}
...
...
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