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


##########
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:
   With the DAO helper gone, this three-line chain is now in all four methods. 
A `private def context = SqlServer.getInstance().createDSLContext()` like the 
other resources would shorten each query. `sessionUser.getUid` can also replace 
`sessionUser.getUser.getUid`, and `getDict` can end with 
`.fetchMap(USER_CONFIG.KEY, USER_CONFIG.VALUE).asScala.toMap`.



##########
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:
   Could the two sums be correlated subqueries instead? That drops the `IN` 
filter, the two derived tables and their joins, and it scans 
`workflow_executions` once instead of three times (there's no index on `uid`).
   
   ```scala
       val resultTotal = DSL.field(
         DSL
           .select(DSL.sum(OPERATOR_PORT_EXECUTIONS.RESULT_SIZE))
           .from(OPERATOR_PORT_EXECUTIONS)
           
.where(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID.eq(WORKFLOW_EXECUTIONS.EID))
       )
   ```
   and the same for `logTotal`. The results matched, including null sizes, 
executions with no rows, and sums past 64 bits.



##########
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:
   This is the same owner-or-granted rule as `WorkflowAccess.accessibleWids`, 
which this file used before. Reusing it keeps one definition of access and is 
much shorter. `WorkflowResource` already uses it this way:
   
   ```scala
       val hasAccessField = DSL
         
.field(WORKFLOW_VERSION.WID.in(WorkflowAccess.accessibleWids(current_user.getUid)))
         .as("has_access")
   ```



-- 
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