Skip to content

Commit

Permalink
Fixed deployment count size
Browse files Browse the repository at this point in the history
  • Loading branch information
GradientTim committed Jan 17, 2023
1 parent 25b12f0 commit 2009693
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
10 changes: 3 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ jar {
)
}

from().duplicatesStrategy = DuplicatesStrategy.EXCLUDE

from(configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude 'META-INF/MANIFEST.MF'
exclude 'META-INF/*.SF'
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
from {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Deployment
deploy_version=1.0.5-RELEASE
deploy_version=1.0.6-RELEASE
deploy_group=net.vounty.wizard
deploy_artifact=Wizard
deploy_url=https://wizard.vounty.net/
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/net/vounty/wizard/repository/WizardRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.*;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

@Getter
@Setter
Expand All @@ -35,6 +37,7 @@ public class WizardRepository implements Repository {
private Visible visible;
private Boolean multipleDeployments;

private transient Map<String, Long> lastDeployment;
private transient Map<String, Deploy> deployments;

public WizardRepository(String name) {
Expand All @@ -48,6 +51,7 @@ public WizardRepository(String name) {
@Override
public Repository updateMissingFields() {
this.deployments = new LinkedHashMap<>();
this.lastDeployment = new LinkedHashMap<>();

if (this.multipleDeployments == null) this.multipleDeployments = false;
if (this.visible == null) this.visible = Visible.PUBLIC;
Expand Down Expand Up @@ -88,14 +92,28 @@ public void download(HttpServletRequest request, Token token, Framework framewor
Spark.halt(403);
}

if (!this.lastDeployment.containsKey(address))
Wizard.getService().getLog().info("User §b{0}§r (§1{1}§r) deploying to repository §b{2}§r...",
token.getUserName(), address, this.getName());

final var deploy = this.deployments.getOrDefault(address, new RepositoryDeploy(folder, new LinkedList<>()));
final var data = new RepositoryData(filePath, inputStream);
final var list = deploy.getDataList();
list.add(data);
if (list.size() >= 25) {
this.flushDeployment(deploy, address, token, framework);
this.deployments.remove(address);
} else this.deployments.put(address, deploy);

this.lastDeployment.put(address, System.currentTimeMillis());
this.deployments.put(address, deploy);

Executors.newSingleThreadScheduledExecutor().schedule(() -> {

final var lastDeployed = this.lastDeployment.getOrDefault(address, System.currentTimeMillis());
if (System.currentTimeMillis() - lastDeployed >= 1000) {
this.flushDeployment(deploy, address, token, framework);
this.deployments.remove(address);
this.lastDeployment.remove(address);
}

}, 2, TimeUnit.SECONDS);
}

private void flushDeployment(Deploy deploy, String address, Token token, Framework framework) {
Expand All @@ -120,7 +138,7 @@ private void flushDeployment(Deploy deploy, String address, Token token, Framewo
}
});

Wizard.getService().getLog().info("User §b{0}§r (§1{1}§r) deploying on §b{2}§r via §1{3}§r",
Wizard.getService().getLog().info("User §b{0}§r (§1{1}§r) deployed on §b{2}§r via §1{3}§r",
token.getUserName(), address, this.getName(), framework);
}

Expand Down

0 comments on commit 2009693

Please sign in to comment.