Skip to content

Commit

Permalink
remove transactional from LocalRegistryService.publish
Browse files Browse the repository at this point in the history
remove merge when persisting file resource
update azure blob storage
Make persistResource synchronized
  • Loading branch information
amvanbaren committed Jul 15, 2023
1 parent 8fbf749 commit 126baf2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 28 deletions.
2 changes: 1 addition & 1 deletion server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def versions = [
springdoc: '2.1.0',
spdx: '2.2.8',
gcloud: '2.22.3',
azure: '12.18.0',
azure: '12.23.0',
guava: '30.0-jre',
junit: '5.7.1',
testcontainers: '1.15.2',
Expand Down
31 changes: 8 additions & 23 deletions server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public ExtensionJson getExtension(String namespace, String extensionName, String
@Cacheable(value = CACHE_EXTENSION_JSON, keyGenerator = GENERATOR_EXTENSION_JSON)
public ExtensionJson getExtension(String namespace, String extensionName, String targetPlatform, String version) {
var extVersion = findExtensionVersion(namespace, extensionName, targetPlatform, version);
var json = toExtensionVersionJson(extVersion, targetPlatform, true, false);
var json = toExtensionVersionJson(extVersion, targetPlatform, true);
json.downloads = getDownloads(extVersion.getExtension(), targetPlatform, extVersion.getVersion());
return json;
}
Expand Down Expand Up @@ -611,24 +611,13 @@ public ResultJson verifyToken(String namespaceName, String tokenValue) {
return ResultJson.success("Valid token");
}

@Retryable(value = { DataIntegrityViolationException.class })
@Transactional(rollbackOn = ErrorResultException.class)
public ExtensionJson publish(InputStream content, UserData user) throws ErrorResultException {
var token = new PersonalAccessToken();
token.setDescription("One time use publish token");
token.setValue(users.generateTokenValue());
token.setCreatedTimestamp(TimeUtil.getCurrentUTC());
token.setAccessedTimestamp(token.getCreatedTimestamp());
token.setUser(user);
token.setActive(true);
entityManager.persist(token);

var json = publish(content, token.getValue());
token.setActive(false);
var token = users.createAccessToken(user, "One time use publish token");
var json = publish(content, token.value);
users.deleteAccessToken(user, token.id);
return json;
}

@Transactional(rollbackOn = ErrorResultException.class)
public ExtensionJson publish(InputStream content, String tokenValue) throws ErrorResultException {
var token = users.useAccessToken(tokenValue);
if (token == null || token.getUser() == null) {
Expand All @@ -639,7 +628,7 @@ public ExtensionJson publish(InputStream content, String tokenValue) throws Erro
eclipse.checkPublisherAgreement(token.getUser());

var extVersion = extensions.publishVersion(content, token);
var json = toExtensionVersionJson(extVersion, null, true, true);
var json = toExtensionVersionJson(extVersion, null, true);
json.success = "It can take a couple minutes before the extension version is available";

var sameVersions = repositories.findVersions(extVersion.getVersion(), extVersion.getExtension());
Expand Down Expand Up @@ -812,14 +801,10 @@ private List<VersionReferenceJson> getAllVersionReferences(
}).collect(Collectors.toList());
}

public ExtensionJson toExtensionVersionJson(ExtensionVersion extVersion, String targetPlatform, boolean onlyActive, boolean inTransaction) {
public ExtensionJson toExtensionVersionJson(ExtensionVersion extVersion, String targetPlatform, boolean onlyActive) {
var extension = extVersion.getExtension();
var latest = inTransaction
? versions.getLatest(extension, targetPlatform, false, onlyActive)
: versions.getLatestTrxn(extension, targetPlatform, false, onlyActive);
var latestPreRelease = inTransaction
? versions.getLatest(extension, targetPlatform, true, onlyActive)
: versions.getLatestTrxn(extension, targetPlatform, true, onlyActive);
var latest = versions.getLatestTrxn(extension, targetPlatform, false, onlyActive);
var latestPreRelease = versions.getLatestTrxn(extension, targetPlatform, true, onlyActive);

var json = extVersion.toExtensionJson();
json.preview = latest != null && latest.isPreview();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public ResponseEntity<ExtensionJson> getExtension(@PathVariable String namespace
json.allVersions = Collections.emptyMap();
json.allTargetPlatformVersions = Collections.emptyMap();
} else {
json = local.toExtensionVersionJson(latest, null, false, false);
json = local.toExtensionVersionJson(latest, null, false);
json.allTargetPlatformVersions = versions.getVersionsTrxn(extension).stream()
.collect(Collectors.groupingBy(ExtensionVersion::getVersion, Collectors.mapping(ExtensionVersion::getTargetPlatform, Collectors.toList())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class PublishExtensionVersionHandler {
@Autowired
ExtensionValidator validator;

@Transactional
@Transactional(rollbackOn = ErrorResultException.class)
public ExtensionVersion createExtensionVersion(ExtensionProcessor processor, PersonalAccessToken token, LocalDateTime timestamp, boolean checkDependencies) {
// Extract extension metadata from its manifest
var extVersion = createExtensionVersion(processor, token.getUser(), token, timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void deleteFileResources(ExtensionVersion extVersion) {
repositories.findFiles(extVersion).forEach(entityManager::remove);
}

@Retryable
public void storeDownload(FileResource download, TempFile extensionFile) {
if (storageUtil.shouldStoreExternally(download)) {
storageUtil.uploadFile(download, extensionFile);
Expand Down Expand Up @@ -78,8 +79,7 @@ public void mirrorResource(FileResource resource) {
}

@Transactional
public void persistResource(FileResource resource) {
resource.setExtension(entityManager.merge(resource.getExtension()));
public synchronized void persistResource(FileResource resource) {
entityManager.persist(resource);
}

Expand Down

0 comments on commit 126baf2

Please sign in to comment.