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


##########
amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowAccessResource.scala:
##########
@@ -81,18 +80,40 @@ object WorkflowAccessResource {
     * @return PrivilegeEnum value indicating NONE/READ/WRITE
     */
   def getPrivilege(wid: Integer, uid: Integer): PrivilegeEnum = {
-    val access = context
-      .select()
-      .from(WORKFLOW_USER_ACCESS)
-      
.where(WORKFLOW_USER_ACCESS.WID.eq(wid).and(WORKFLOW_USER_ACCESS.UID.eq(uid)))
-      .fetchOneInto(classOf[WorkflowUserAccess])
-    if (access == null) {
-      PrivilegeEnum.NONE
-    } else {
-      access.getPrivilege
-    }
+    // One round trip: the caller's own ownership row and grant, read 
together. Both joins are
+    // narrowed to the caller, so a workflow with several owners still yields 
one row.
+    val row = context
+      .select(WORKFLOW_OF_USER.UID, WORKFLOW_USER_ACCESS.PRIVILEGE)
+      .from(WORKFLOW)
+      .leftJoin(WORKFLOW_OF_USER)
+      
.on(WORKFLOW_OF_USER.WID.eq(WORKFLOW.WID).and(WORKFLOW_OF_USER.UID.eq(uid)))
+      .leftJoin(WORKFLOW_USER_ACCESS)
+      
.on(WORKFLOW_USER_ACCESS.WID.eq(WORKFLOW.WID).and(WORKFLOW_USER_ACCESS.UID.eq(uid)))
+      .where(WORKFLOW.WID.eq(wid))
+      .fetchOne()
+    if (row == null) PrivilegeEnum.NONE
+    else OwnerAccess.privilege(row.value1() != null, row.value2())
   }
 
+  def isOwner(wid: Integer, uid: Integer): Boolean =
+    context.fetchExists(
+      WORKFLOW_OF_USER,
+      WORKFLOW_OF_USER.WID.eq(wid).and(WORKFLOW_OF_USER.UID.eq(uid))
+    )

Review Comment:
   This is the same check as `WorkflowResource.workflowOfUserExists`, which the 
persist and delete paths use, so the two could share one. Also, now that the 
owner is WRITE, `updateWorkflowField`'s `workflowOfUserExists(...) || 
hasWriteAccess(...)` reduces to `hasWriteAccess(...)`. Today a non-owner pays 
an extra query on every field update.



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