Merge pull request #3964 from overleaf/jpa-unique-project-name-with-year

[ProjectHelper] _addNumericSuffixToProjectName: add heuristic for year

GitOrigin-RevId: 24c57d68706bdabba620137674946e3c8e675939
This commit is contained in:
Shane Kilkelly
2021-05-01 02:13:10 +00:00
committed by Copybot
parent 3c9cd69bfa
commit 6893cce6c9
2 changed files with 30 additions and 0 deletions
@@ -141,6 +141,16 @@ function _addNumericSuffixToProjectName(name, allProjectNames, maxLength) {
n = parseInt(match[1])
}
const prefixMatcher = new RegExp(`^${basename} \\(\\d+\\)$`)
const projectNamesWithSamePrefix = Array.from(allProjectNames).filter(name =>
prefixMatcher.test(name)
)
const nIsLikelyAYear = n > 1000 && projectNamesWithSamePrefix.length < n / 2
if (nIsLikelyAYear) {
basename = name
n = 1
}
while (n <= last) {
const candidate = suffixedName(basename, n)
if (!allProjectNames.has(candidate)) {