aglinxinyuan commented on code in PR #9476:
URL: https://github.com/apache/texera/pull/9476#discussion_r4592776459


##########
amber/src/main/scala/org/apache/texera/web/resource/UserConfigResource.scala:
##########
@@ -34,77 +32,53 @@ import scala.jdk.CollectionConverters.CollectionHasAsScala
 /**
   * This class handles requests to read and write the user dictionary,
   * an abstract collection of (key, value) string pairs that is unique for 
each user
-  * This is accomplished using a mysql table called user_dictionary.
-  * The details of user_dictionary can be found in /sql/texera_ddl.sql
+  * This is accomplished using a table called user_config.
+  * The details of user_config can be found in /sql/texera_ddl.sql
   */
 @Path("/user/config")
 @RolesAllowed(Array("REGULAR", "ADMIN"))
 @Consumes(Array(MediaType.TEXT_PLAIN))
 class UserConfigResource {
-  private def userDictionaryDao =
-    new UserConfigDao(
-      SqlServer
-        .getInstance()
-        .createDSLContext()
-        .configuration
-    )
+  private def requireValidKey(key: String): Unit =
+    if (key == null || key.trim.isEmpty) {
+      throw new BadRequestException("key cannot be null or empty")
+    }
 
   @GET
   @Produces(Array(MediaType.APPLICATION_JSON))
   def getAllDict(@Auth sessionUser: SessionUser): Map[String, String] = {
-    val user = sessionUser.getUser
-    getDict(user)
+    getDict(sessionUser.getUser.getUid)
   }
 
   /**
     * This method retrieves all of a user's dictionary entries in
-    * the user_dictionary table as a json object
+    * the user_config table as a json object
     */
-  private def getDict(user: User): Map[String, String] = {
+  private def getDict(uid: Integer): Map[String, String] = {
     SqlServer
       .getInstance()
       .createDSLContext()

Review Comment:
   Done in 812571ae49. The four methods now share a `context` helper and read 
the uid through `sessionUser.getUid`, and `getDict` ends with 
`.fetchMap(USER_CONFIG.KEY, USER_CONFIG.VALUE).asScala.toMap`.



##########
amber/src/main/scala/org/apache/texera/web/resource/dashboard/admin/execution/AdminExecutionResource.scala:
##########
@@ -129,6 +124,34 @@ class AdminExecutionResource {
   ): List[dashboardExecution] = {
     val filter_status = filter.asScala.map(mapToStatus).toSeq.filter(_ != 
-1).asJava
 
+    val hasAccessField = DSL
+      .field(
+        DSL
+          .exists(
+            DSL
+              .selectOne()
+              .from(WORKFLOW_OF_USER)
+              .where(
+                WORKFLOW_OF_USER.UID
+                  .eq(current_user.getUid)
+                  .and(WORKFLOW_OF_USER.WID.eq(WORKFLOW_VERSION.WID))
+              )
+          )
+          .or(
+            DSL.exists(
+              DSL
+                .selectOne()
+                .from(WORKFLOW_USER_ACCESS)
+                .where(
+                  WORKFLOW_USER_ACCESS.UID
+                    .eq(current_user.getUid)
+                    .and(WORKFLOW_USER_ACCESS.WID.eq(WORKFLOW_VERSION.WID))
+                )
+            )
+          )
+      )
+      .as("has_access")

Review Comment:
   Done in 812571ae49. The flag is now 
`WORKFLOW_VERSION.WID.in(WorkflowAccess.accessibleWids(current_user.getUid))`, 
so the owner-or-grant rule has a single definition again.



##########
amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResource.scala:
##########
@@ -106,62 +106,68 @@ object UserQuotaResource {
   }
 
   def getUserQuotaSize(uid: Integer): Array[QuotaStorage] = {
-    val executions = context
+    val userExecutions = DSL
+      .select(WORKFLOW_EXECUTIONS.EID)
+      .from(WORKFLOW_EXECUTIONS)
+      .where(WORKFLOW_EXECUTIONS.UID.eq(uid))
+
+    val resultSize = 
DSL.sum(OPERATOR_PORT_EXECUTIONS.RESULT_SIZE).as("result_size")
+    val resultSizes = DSL
+      .select(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID, resultSize)
+      .from(OPERATOR_PORT_EXECUTIONS)
+      .where(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID.in(userExecutions))
+      .groupBy(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID)
+      .asTable("result_sizes")
+
+    val logSize = 
DSL.sum(OPERATOR_EXECUTIONS.CONSOLE_MESSAGES_SIZE).as("log_size")
+    val logSizes = DSL
+      .select(OPERATOR_EXECUTIONS.WORKFLOW_EXECUTION_ID, logSize)
+      .from(OPERATOR_EXECUTIONS)
+      .where(OPERATOR_EXECUTIONS.WORKFLOW_EXECUTION_ID.in(userExecutions))
+      .groupBy(OPERATOR_EXECUTIONS.WORKFLOW_EXECUTION_ID)
+      .asTable("log_sizes")
+
+    val resultTotal = resultSizes.field(resultSize)
+    val logTotal = logSizes.field(logSize)

Review Comment:
   Done in 812571ae49. Both totals are now correlated subqueries, so the `IN` 
filter, the two derived tables, and their joins are gone. A local probe also 
matched for null and missing sizes, rows from another user, and a sum past 64 
bits.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to