Skip to content

Commit

Permalink
Repair: remove database size condition check, update: small code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
themitosan committed Dec 16, 2024
1 parent 978565f commit b2db154
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
1 change: 0 additions & 1 deletion Lang/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
"repair": {

"warnUnablePerformRepair": "AVISO - Não foi possível realizar reparo!\nMotivo: %VAR_0%",
"warnUnablePerformRepair_noRepos": "Não há repositórios no banco de dados!",

"infoCheckDatabaseFiles": "INFO - Verificando lista de repositórios...",

Expand Down
1 change: 0 additions & 1 deletion src/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export var langDatabase:any = {
"repair": {

"warnUnablePerformRepair": "WARN - Unable to perform repair!\nReason: %VAR_0%",
"warnUnablePerformRepair_noRepos": "There is no repos on database!",

"infoCheckDatabaseFiles": "INFO - Checking repo list...",

Expand Down
3 changes: 0 additions & 3 deletions src/repair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ export async function grpp_startRepairDatabase(){
repoList = structuredClone([...Object.keys(grppSettings.repoEntries)]);

// Test conditions to not run repair process
if (repoList.length === 0) reasonList.push(langDatabase.repair.warnUnablePerformRepair_noRepos);
if (module_fs.existsSync(`${process.cwd()}/.temp/`) === !0) reasonList.push(langDatabase.common.errorBatchUpdateRunning);

// Check if can start repair process
execReasonListCheck(reasonList, langDatabase.repair.warnUnablePerformRepair, async function(){

// Filter git folders
Expand Down
68 changes: 40 additions & 28 deletions src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,47 +203,59 @@ export async function grpp_processBatchFile(id:number){
}

/**
* Start GRPP update process
* Sort repos to be updatd
* @param repoList [string[]] List to be sorted
* @returns [string[]] New list with sorted items
*/
async function grpp_startBatchUpdate(){
async function grpp_sortBatchList(repoList:string[]):Promise<string[]> {
return new Promise<string[]>(function(resolve){

// Declare vars
var completedRunners = 0,
updateList:string[] = [],
priorityRepos:string[] = [];
var updateList:string[] = [],
priorityRepos:string[] = [];

// Set current time to measure update time, set tempDir var and check if it exists. If so, remove it and create a new one
tempDir = structuredClone(`${process.cwd()}/.temp`);
startUpdateTime = structuredClone(performance.now());
if (module_fs.existsSync(tempDir) === !0) module_fs.rmSync(tempDir, { recursive: !0 });
module_fs.mkdirSync(tempDir);
repoList.forEach(function(currentRepo){

// Filter repos that cannot be updated
createLogEntry(`INFO - Creating update list...`);
Object.keys(grppSettings.repoEntries).forEach(function(currentRepo){
// Get current repo data and check if can update
const repoData:grppRepoEntry = grppSettings.repoEntries[currentRepo];
if (repoData.canUpdate === !0){

// Get current repo data and check if can update
const repoData:grppRepoEntry = grppSettings.repoEntries[currentRepo];
if (repoData.canUpdate === !0){
if (repoData.isPriority === !0){
priorityRepos.push(currentRepo);
} else {
updateList.push(currentRepo);
}
totalReposQueued++;

if (repoData.isPriority === !0){
priorityRepos.push(currentRepo);
} else {
updateList.push(currentRepo);
skippedRepos.push(currentRepo);
}
totalReposQueued++;

} else {
skippedRepos.push(currentRepo);
}
});

// Put priority repos first if priority list isn't empty and return sorted list
if (priorityRepos.length !== 0) updateList = [ ...priorityRepos, ...updateList ];
resolve(updateList);

});
}

// Put priority repos first if priority list isn't empty
if (priorityRepos.length !== 0) updateList = [ ...priorityRepos, ...updateList ];
/**
* Start GRPP update process
*/
async function grpp_startBatchUpdate(){

// Split update list on given runners, create GRPP batch files and set total res files / queued repos vars
const chunkList = spliceArrayIntoChunks(updateList, grppSettings.maxReposPerList);
// Set current time to measure update time, set tempDir var and check if it exists. If so, remove it and create a new one
var completedRunners = 0;
tempDir = structuredClone(`${process.cwd()}/.temp`);
startUpdateTime = structuredClone(performance.now());
if (module_fs.existsSync(tempDir) === !0) module_fs.rmSync(tempDir, { recursive: !0 });
module_fs.mkdirSync(tempDir);

// Split update list on given runners, create GRPP batch file and set total res files / queued repos vars
createLogEntry(`INFO - Creating update list...`);
const
updateList = await grpp_sortBatchList(Object.keys(grppSettings.repoEntries)),
chunkList = spliceArrayIntoChunks(updateList, grppSettings.maxReposPerList);
module_fs.writeFileSync(`${tempDir}/GRPP_BATCH.json`, JSON.stringify({ batchList: chunkList }), 'utf-8');
totalResFiles = structuredClone(chunkList.length);

Expand Down

0 comments on commit b2db154

Please sign in to comment.