Skip to content

Commit

Permalink
Merge pull request #976 from amvanbaren/optimize-db-queries
Browse files Browse the repository at this point in the history
Optimize database queries
  • Loading branch information
amvanbaren authored Aug 19, 2024
2 parents 33d9da2 + 61c1ad3 commit beae7fd
Show file tree
Hide file tree
Showing 46 changed files with 1,386 additions and 752 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** ******************************************************************************
* Copyright (c) 2024 Precies. Software OU and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
* ****************************************************************************** */
package org.eclipse.openvsx

import io.gatling.core.Predef._
import org.eclipse.openvsx.Scenarios._

class RegistryAPIGetVersionReferencesSimulation extends Simulation {
setUp(getVersionReferencesScenario().inject(atOnceUsers(users))).protocols(httpProtocol)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** ******************************************************************************
* Copyright (c) 2024 Precies. Software OU and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
* ****************************************************************************** */
package org.eclipse.openvsx

import io.gatling.core.Predef._
import org.eclipse.openvsx.Scenarios._

class RegistryAPIGetVersionReferencesTargetPlatformSimulation extends Simulation {
setUp(getVersionReferencesTargetPlatformScenario().inject(atOnceUsers(users))).protocols(httpProtocol)
}
65 changes: 44 additions & 21 deletions server/src/gatling/scala/org/eclipse/openvsx/Scenarios.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ object Scenarios {
.exec(http("RegistryAPI.createNamespace")
.post(s"/api/-/namespace/create")
.headers(headers())
.queryParam("token", """${access_token}""")
.body(StringBody("""{"name":"${namespace}"}""")).asJson
.queryParam("token", """#{access_token}""")
.body(StringBody("""{"name":"#{namespace}"}""")).asJson
.requestTimeout(3.minutes)
.check(status.is(201)))
// useful for debugging responses
Expand Down Expand Up @@ -95,7 +95,7 @@ object Scenarios {
.exec(http("RegistryAPI.publish")
.post("/api/-/publish")
.headers(headers())
.queryParam("token", """${access_token}""")
.queryParam("token", """#{access_token}""")
.body(ByteArrayBody(session => {
val path = extensionDir + "\\" + session("extension_file").as[String]
File(path).toByteArray()
Expand Down Expand Up @@ -123,10 +123,10 @@ object Scenarios {
!File(extensionFile).exists
}) {
exec(http("getExtensionDownloadLink")
.get("""/api/${namespace}/${name}/${version}""")
.get("""/api/#{namespace}/#{name}/#{version}""")
.check(jsonPath("$.files.download").find.saveAs("download")))
.exec(http("downloadExtension")
.get("""${download}""")
.get("""#{download}""")
.check(bodyBytes.saveAs("file_bytes")))
.pause(30, 60)
.exec {session =>
Expand All @@ -142,7 +142,7 @@ object Scenarios {
.repeat(1000) {
feed(csv("extensions.csv").circular)
.exec(http("RegistryAPI.getExtension")
.get("""/api/${namespace}/${name}""")
.get("""/api/#{namespace}/#{name}""")
.headers(headers()))
// .check(status.is(200)))
}
Expand All @@ -154,7 +154,7 @@ object Scenarios {
.repeat(1000) {
feed(csv("extensions.csv").circular)
.exec(http("RegistryAPI.getExtension")
.get("""/api/${namespace}/${name}/universal""")
.get("""/api/#{namespace}/#{name}/universal""")
.headers(headers()))
// .check(status.is(200)))
}
Expand All @@ -165,7 +165,7 @@ object Scenarios {
.repeat(1000) {
feed(csv("extension-versions.csv").circular)
.exec(http("RegistryAPI.getExtension")
.get("""/api/${namespace}/${name}/${version}""")
.get("""/api/#{namespace}/#{name}/#{version}""")
.headers(headers()))
// .check(status.is(200)))
}
Expand All @@ -177,7 +177,30 @@ object Scenarios {
.repeat(1000) {
feed(csv("extension-versions.csv").circular)
.exec(http("RegistryAPI.getExtension")
.get("""/api/${namespace}/${name}/universal/${version}""")
.get("""/api/#{namespace}/#{name}/universal/#{version}""")
.headers(headers()))
// .check(status.is(200)))
}
}

def getVersionReferencesScenario(): ScenarioBuilder = {
scenario("RegistryAPI: Get Version References")
.repeat(1000) {
feed(csv("extensions.csv").circular)
.exec(http("RegistryAPI.getVersionReferences")
.get("""/api/#{namespace}/#{name}/version-references""")
.headers(headers()))
// .check(status.is(200)))
}
}

def getVersionReferencesTargetPlatformScenario(): ScenarioBuilder = {
// TODO add more target platforms besides 'universal'
scenario("RegistryAPI: Get Version References by Target Platform")
.repeat(1000) {
feed(csv("extensions.csv").circular)
.exec(http("RegistryAPI.getVersionReferences")
.get("""/api/#{namespace}/#{name}/universal/version-references""")
.headers(headers()))
// .check(status.is(200)))
}
Expand All @@ -188,7 +211,7 @@ object Scenarios {
.repeat(1000) {
feed(csv("namespaces.csv").circular)
.exec(http("RegistryAPI.getNamespace")
.get("""/api/${namespace}""")
.get("""/api/#{namespace}""")
.headers(headers())
.check(status.is(200)))
}
Expand All @@ -199,7 +222,7 @@ object Scenarios {
.repeat(1000) {
feed(csv("namespaces.csv").circular)
.exec(http("RegistryAPI.getNamespaceDetails")
.get("""/api/${namespace}/details""")
.get("""/api/#{namespace}/details""")
.headers(headers())
.check(status.is(200)))
}
Expand All @@ -210,7 +233,7 @@ object Scenarios {
.repeat(1000) {
feed(csv("query-strings.csv").circular)
.exec(http("RegistryAPI.getQuery")
.get("""/api/-/query?${query}""")
.get("""/api/-/query?#{query}""")
.headers(headers())
.check(status.is(200)))
}
Expand All @@ -221,7 +244,7 @@ object Scenarios {
.repeat(1000) {
feed(csv("query-v2-strings.csv").circular)
.exec(http("RegistryAPI.getQueryV2")
.get("""/api/v2/-/query?${query}""")
.get("""/api/v2/-/query?#{query}""")
.headers(headers())
.check(status.is(200)))
}
Expand Down Expand Up @@ -260,7 +283,7 @@ object Scenarios {
.repeat(1000) {
feed(csv("extension-versions.csv").circular)
.feed(Array(
Map("file" -> """${namespace}.${name}-${version}.vsix"""),
Map("file" -> """#{namespace}.#{name}-#{version}.vsix"""),
Map("file" -> "package.json"),
Map("file" -> "extension.vsixmanifest"),
Map("file" -> "CHANGELOG.md"),
Expand Down Expand Up @@ -347,7 +370,7 @@ object Scenarios {
.repeat(1000) {
feed(this.searchQueryFeeder().circular)
.exec(http("RegistryAPI.search")
.get("""/api/-/search?${query}""")
.get("""/api/-/search?#{query}""")
.headers(headers()))
// .check(status.is(200)))
}
Expand All @@ -359,7 +382,7 @@ object Scenarios {
feed(csv("namespaces.csv").circular)
.feed(csv("access-tokens.csv").circular)
.exec(http("RegistryAPI.verifyToken")
.get("""/api/${namespace}/verify-pat?token=${access_token}""")
.get("""/api/#{namespace}/verify-pat?token=#{access_token}""")
.headers(headers())
.requestTimeout(3.minutes))
}
Expand All @@ -375,7 +398,7 @@ object Scenarios {
| {
| "criteria":[
| {"filterType":8,"value":"Microsoft.VisualStudio.Code"},
| {"filterType":10,"value":"${query}"},
| {"filterType":10,"value":"#{query}"},
| {"filterType":12,"value":"4096"}
| ],
| "pageNumber":1,
Expand Down Expand Up @@ -409,7 +432,7 @@ object Scenarios {
.repeat(1000) {
feed(csv("extension-versions.csv").circular)
.exec(http("VSCodeAdapter.download")
.get("""/vscode/gallery/publishers/${namespace}/vsextensions/${name}/${version}/vspackage""")
.get("""/vscode/gallery/publishers/#{namespace}/vsextensions/#{name}/#{version}/vspackage""")
.headers(headers())
.requestTimeout(3.minutes)
.check(status.is(200)))
Expand All @@ -421,7 +444,7 @@ object Scenarios {
.repeat(1000) {
feed(csv("extensions.csv").circular)
.exec(http("VSCodeAdapter.getItemUrl")
.get("""/vscode/item?itemName=${namespace}.${name}""")
.get("""/vscode/item?itemName=#{namespace}.#{name}""")
.headers(headers())
.requestTimeout(3.minutes)
.check(status.is(200)))
Expand All @@ -434,7 +457,7 @@ object Scenarios {
feed(csv("extension-versions.csv").circular)
.feed(Array(Map("file" -> "extension.vsixmanifest"), Map("file" -> "extension")).circular)
.exec(http("VSCodeAdapter.browse")
.get("""/vscode/unpkg/${namespace}/${name}/${version}/${file}""")
.get("""/vscode/unpkg/#{namespace}/#{name}/#{version}/#{file}""")
.headers(headers())
.requestTimeout(3.minutes)
.check(status.is(200)))
Expand All @@ -455,7 +478,7 @@ object Scenarios {
Map("asset" -> "Microsoft.VisualStudio.Code.WebResources/extension/package.json")
).circular)
.exec(http("VSCodeAdapter.getAsset")
.get("""/vscode/asset/${namespace}/${name}/${version}/${asset}""")
.get("""/vscode/asset/#{namespace}/#{name}/#{version}/#{asset}""")
.headers(headers())
.requestTimeout(3.minutes)
.check(status.is(200)))
Expand Down
2 changes: 2 additions & 0 deletions server/src/gatling/scripts/test-registry-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ cd ../../..
./gradlew --rerun-tasks gatlingRun-org.eclipse.openvsx.RegistryAPIGetExtensionTargetPlatformSimulation
./gradlew --rerun-tasks gatlingRun-org.eclipse.openvsx.RegistryAPIGetExtensionVersionSimulation
./gradlew --rerun-tasks gatlingRun-org.eclipse.openvsx.RegistryAPIGetExtensionVersionTargetPlatformSimulation
./gradlew --rerun-tasks gatlingRun-org.eclipse.openvsx.RegistryAPIGetVersionReferencesSimulation
./gradlew --rerun-tasks gatlingRun-org.eclipse.openvsx.RegistryAPIGetVersionReferencesTargetPlatformSimulation
./gradlew --rerun-tasks gatlingRun-org.eclipse.openvsx.RegistryAPIGetFileSimulation
./gradlew --rerun-tasks gatlingRun-org.eclipse.openvsx.RegistryAPIGetFileTargetPlatformSimulation
./gradlew --rerun-tasks gatlingRun-org.eclipse.openvsx.RegistryAPIGetQuerySimulation
Expand Down
11 changes: 4 additions & 7 deletions server/src/main/java/org/eclipse/openvsx/ExtensionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,11 @@ public void updateExtension(Extension extension) {
*/
@Transactional
public void reactivateExtensions(UserData user) {
var accessTokens = repositories.findAccessTokens(user);
var affectedExtensions = new LinkedHashSet<Extension>();
for (var accessToken : accessTokens) {
var versions = repositories.findVersionsByAccessToken(accessToken, false);
for (var version : versions) {
version.setActive(true);
affectedExtensions.add(version.getExtension());
}
var versions = repositories.findVersionsByUser(user, false);
for (var version : versions) {
version.setActive(true);
affectedExtensions.add(version.getExtension());
}
for (var extension : affectedExtensions) {
updateExtension(extension);
Expand Down
Loading

0 comments on commit beae7fd

Please sign in to comment.