bobbai00 commented on code in PR #9226:
URL: https://github.com/apache/texera/pull/9226#discussion_r4596029860


##########
amber/src/main/scala/org/apache/texera/web/resource/dashboard/hub/HubResource.scala:
##########
@@ -418,7 +418,9 @@ class HubResource {
       .returning(viewCountColumn)
       .fetchOne()
 
-    recordUserAction(request, userId, entityID, entityType, View)
+    // An anonymous viewer has no user row, so the view is recorded with a 
NULL uid.
+    val viewerUid = Option(userId).filter(_.intValue() > 0).orNull
+    recordUserAction(request, viewerUid, entityID, entityType, View)

Review Comment:
   **Advisory:**
   
   The count bump at [line 
412](https://github.com/apache/texera/blob/477e26596ac590958b11f9bb46cbf54c9527d39d/amber/src/main/scala/org/apache/texera/web/resource/dashboard/hub/HubResource.scala#L412)
 and this insert commit separately. So a failed insert still returns 500 after 
the count went up, the mechanism behind #9225. One trigger is left: a uid whose 
user row is gone 
([`adoptPlaceholder`](https://github.com/apache/texera/blob/477e26596ac590958b11f9bb46cbf54c9527d39d/amber/src/main/scala/org/apache/texera/web/resource/auth/AuthResource.scala#L288)
 deletes accounts, and another open tab can still send that uid). Wrapping both 
writes in 
[`SqlServer.withTransaction`](https://github.com/apache/texera/blob/477e26596ac590958b11f9bb46cbf54c9527d39d/common/dao/src/main/scala/org/apache/texera/dao/SqlServer.scala#L96)
 closes it for every trigger. Fine as a follow-up.



##########
amber/src/main/scala/org/apache/texera/web/resource/dashboard/hub/HubResource.scala:
##########
@@ -418,7 +418,9 @@ class HubResource {
       .returning(viewCountColumn)
       .fetchOne()
 
-    recordUserAction(request, userId, entityID, entityType, View)
+    // An anonymous viewer has no user row, so the view is recorded with a 
NULL uid.
+    val viewerUid = Option(userId).filter(_.intValue() > 0).orNull

Review Comment:
   **Advisory:**
   
   `.orNull` and the new `= null` default put a null sentinel in the Scala API. 
The IP column shows the null-free shape: it is set only when present ([line 
165](https://github.com/apache/texera/blob/477e26596ac590958b11f9bb46cbf54c9527d39d/amber/src/main/scala/org/apache/texera/web/resource/dashboard/hub/HubResource.scala#L165)).
 With `userId: Option[Integer] = None` and 
`userId.foreach(query.set(USER_ACTION.UID, _))`, this line becomes 
`Option(userId).filter(_.intValue() > 0)`. The new "omitted" test still passes.



##########
amber/src/test/scala/org/apache/texera/web/resource/dashboard/hub/HubResourceSpec.scala:
##########
@@ -453,6 +453,13 @@ class HubResourceSpec
     auditRows() shouldBe Seq((Integer.valueOf(ownerUid), "workflow", 810102, 
"clone", null))
   }
 
+  it should "store a NULL uid when userId is omitted" in {

Review Comment:
   **Advisory:**
   
   
[AGENTS.md](https://github.com/apache/texera/blob/main/AGENTS.md#branch-and-commit-naming)
 asks for a module scope and about 60 characters, since the title becomes the 
squash commit. This title is 78 characters with the feature scope `hub`. 
Suggested: `fix(amber): store anonymous hub views with a NULL uid`.



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