You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by "DanielAuerX (via GitHub)" <gi...@apache.org> on 2025/05/09 13:31:13 UTC

[PR] Fix file record and delete files (branding and avatar) [answer]

DanielAuerX opened a new pull request, #1335:
URL: https://github.com/apache/answer/pull/1335

   - [ ] create file_record table
   - [ ] avatar and branding files are added to file_record
   - [ ] branding files are being deleted
   - [ ] avatar files are being deleted


-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "DanielAuerX (via GitHub)" <gi...@apache.org>.
DanielAuerX commented on code in PR #1335:
URL: https://github.com/apache/answer/pull/1335#discussion_r2091264274


##########
ui/src/pages/Users/Settings/Profile/index.tsx:
##########
@@ -241,10 +241,7 @@ const Index: React.FC = () => {
 
     modifyUserInfo(params)
       .then(() => {
-        update({
-          ...user,
-          ...params,
-        });
+        getLoggedUserInfo().then(update);

Review Comment:
   + checkout branch
   + remove the commit in question
   + upload a custom avatar
   + update the custom avatar with another avatar
   + check the logs and/or the uploads/avatar/ get requests



##########
internal/service/siteinfo/siteinfo_service.go:
##########
@@ -438,3 +442,43 @@ func (s *SiteInfoService) UpdatePrivilegesConfig(ctx context.Context, req *schem
 	}
 	return
 }
+
+func (s *SiteInfoService) CleanUpRemovedBrandingFiles(
+	ctx context.Context,
+	newBranding *schema.SiteBrandingReq,
+	currentBranding *schema.SiteBrandingResp,
+) error {

Review Comment:
   returning all errors now, so that the log (in the controller) provides information on the file(s) that caused an error



##########
ui/src/pages/Users/Settings/Profile/index.tsx:
##########
@@ -241,10 +241,7 @@ const Index: React.FC = () => {
 
     modifyUserInfo(params)
       .then(() => {
-        update({
-          ...user,
-          ...params,
-        });
+        getLoggedUserInfo().then(update);

Review Comment:
   my response is still pending, idk why:
   
   - checkout branch
   - remove the commit in question
   - upload a custom avatar
   - update the custom avatar with another avatar
   - check the logs and/or the uploads/avatar/ get requests
   
   
   



-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "shuashuai (via GitHub)" <gi...@apache.org>.
shuashuai commented on code in PR #1335:
URL: https://github.com/apache/answer/pull/1335#discussion_r2097274956


##########
ui/src/pages/Users/Settings/Profile/index.tsx:
##########
@@ -241,10 +241,7 @@ const Index: React.FC = () => {
 
     modifyUserInfo(params)
       .then(() => {
-        update({
-          ...user,
-          ...params,
-        });
+        getLoggedUserInfo().then(update);

Review Comment:
   > Just for clarification, this change is not supposed to eliminate browser cache. Its supposed to be updating the user information, so an old avatar file is not being requested after it has been removed from the user information. This is not new behavior. However, previously requesting an old resource was successful, because files were not being deleted.
   
   Both ways of updating the user's information are the same and there is no practical difference between them!
   
   > Do you have a better solution? I can also just remove the commit, if you think this is acceptable.
   
   There is no better way at the moment, so let's keep the previous logic for the time being.
   
   
   



-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "DanielAuerX (via GitHub)" <gi...@apache.org>.
DanielAuerX commented on code in PR #1335:
URL: https://github.com/apache/answer/pull/1335#discussion_r2097259369


##########
ui/src/pages/Users/Settings/Profile/index.tsx:
##########
@@ -241,10 +241,7 @@ const Index: React.FC = () => {
 
     modifyUserInfo(params)
       .then(() => {
-        update({
-          ...user,
-          ...params,
-        });
+        getLoggedUserInfo().then(update);

Review Comment:
   > I tested it and found that this modification still cannot eliminate browser cache unless the entire application is reloaded using `window.reload`, however, using this method will affect the user's experience.
   
   @shuashuai Just for clarification, this change is not supposed to eliminate browser cache. Its supposed to be updating the user information, so an old avatar file is not being requested after it has been removed from the user information. This is not new behavior. However, previously requesting an old resource was successful, because files were not being deleted.
   
   Do you have a better solution? I can also just remove the commit, if you think this is acceptable.
   



-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "shuashuai (via GitHub)" <gi...@apache.org>.
shuashuai commented on code in PR #1335:
URL: https://github.com/apache/answer/pull/1335#discussion_r2096785703


##########
ui/src/pages/Users/Settings/Profile/index.tsx:
##########
@@ -241,10 +241,7 @@ const Index: React.FC = () => {
 
     modifyUserInfo(params)
       .then(() => {
-        update({
-          ...user,
-          ...params,
-        });
+        getLoggedUserInfo().then(update);

Review Comment:
   > * checkout branch
   > * remove the commit in question
   > * upload a custom avatar
   > * update the custom avatar with another avatar
   > * check the logs and/or the uploads/avatar/ get requests
   
   I tested it and found that this modification still cannot eliminate browser cache unless the entire application is reloaded using `window.reload`, however, using this method will affect the user's experience.
   
   Because from the perspective of generation implementation, updating user information after obtaining from get interface is the same as updating from params, and it cannot eliminate browser cache.
   
   Here are the steps I tested with your code:
   1. upload a custom avatar and save
   2. reupload a custom avatar and save
   3. Return to the question list page, and the last avatar will still be retrieved from the cache (you can see from the console's get request).
   
   
   
   
   



-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "DanielAuerX (via GitHub)" <gi...@apache.org>.
DanielAuerX commented on PR #1335:
URL: https://github.com/apache/answer/pull/1335#issuecomment-2887707003

   > @DanielAuerX
   > 
   > For issue 2, here are my reproduction steps.
   > 
   > 1. Upload an avatar and save the profile.
   > 2. Check the avatar dir. (The file exists)
   > 3. Switch the avatar to system and save the profile.
   > 4. Check the avatar dir. (The file not exists)
   > 
   > ```
   > 1. ➜  avatar git:(fix_file_record) ls
   > 2. ➜  avatar git:(fix_file_record) ls
   > 5sVCXwyhsbm.png
   > 4. ➜  avatar git:(fix_file_record) ls
   > ➜  avatar git:(fix_file_record) 
   > ```
   > 
   > This is the reason for the problem.
   > 
   > ```go
   > if oldAvatar.Type == "custom" && (newAvatar.Type != "custom" || oldAvatar.Custom != newAvatar.Custom) {
   > ```
   > 
   > At this time, `newAvatar.Type != "custom"` so the file will be deleted.
   > 
   > To make the logic simple, perhaps it could be implemented like this.
   > 
   > ```go
   > 	// As long as there are no original files, there must be no need to delete
   > 	if len(oldAvatar.Custom) == 0 {
   > 		return
   > 	}
   > 	// At this point, it turns out that the old file must exist. 
   > 	// Then delete as long as the new file and the old file are inconsistent as you say. 
   > 	// Whatever type the user chooses.
   > 	if oldAvatar.Custom != newAvatar.Custom {
   > 		fileRecord, err := us.fileRecordService.GetFileRecordByURL(ctx, oldAvatar.Custom)
   > 	}
   > ```
   
   Should be done now


-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars merged PR #1335:
URL: https://github.com/apache/answer/pull/1335


-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars commented on code in PR #1335:
URL: https://github.com/apache/answer/pull/1335#discussion_r2094743959


##########
ui/src/pages/Users/Settings/Profile/index.tsx:
##########
@@ -241,10 +241,7 @@ const Index: React.FC = () => {
 
     modifyUserInfo(params)
       .then(() => {
-        update({
-          ...user,
-          ...params,
-        });
+        getLoggedUserInfo().then(update);

Review Comment:
   @DanielAuerX This is the only problem left in this PR. Are there any suitable steps to reproduce this problem?



-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "DanielAuerX (via GitHub)" <gi...@apache.org>.
DanielAuerX commented on code in PR #1335:
URL: https://github.com/apache/answer/pull/1335#discussion_r2095657638


##########
ui/src/pages/Users/Settings/Profile/index.tsx:
##########
@@ -241,10 +241,7 @@ const Index: React.FC = () => {
 
     modifyUserInfo(params)
       .then(() => {
-        update({
-          ...user,
-          ...params,
-        });
+        getLoggedUserInfo().then(update);

Review Comment:
   my response is still pending, idk why:
   
   - checkout branch
   - remove the commit in question
   - upload a custom avatar
   - update the custom avatar with another avatar
   - check the logs and/or the uploads/avatar/ get requests
   
   
   



-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "DanielAuerX (via GitHub)" <gi...@apache.org>.
DanielAuerX commented on PR #1335:
URL: https://github.com/apache/answer/pull/1335#issuecomment-2877432626

   Hi @LinkinStars! yes, the tasks of this pr are finished, unless you see something I missed.
   The clean up job (CleanOrphanUploadFiles) is running now. However, I am not sure that it works as intended when it was implemented. Maybe you want to double check that. 


-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars commented on PR #1335:
URL: https://github.com/apache/answer/pull/1335#issuecomment-2875477775

   Thanks for contributing. As a reminder, I see that all tasks have been completed, so if you need to review, please change the draft status to ready.


-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "shuashuai (via GitHub)" <gi...@apache.org>.
shuashuai commented on code in PR #1335:
URL: https://github.com/apache/answer/pull/1335#discussion_r2094744128


##########
ui/src/pages/Users/Settings/Profile/index.tsx:
##########
@@ -241,10 +241,7 @@ const Index: React.FC = () => {
 
     modifyUserInfo(params)
       .then(() => {
-        update({
-          ...user,
-          ...params,
-        });
+        getLoggedUserInfo().then(update);

Review Comment:
   @DanielAuerX  wait for your reply!



-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars commented on code in PR #1335:
URL: https://github.com/apache/answer/pull/1335#discussion_r2096796582


##########
ui/src/pages/Users/Settings/Profile/index.tsx:
##########
@@ -241,10 +241,7 @@ const Index: React.FC = () => {
 
     modifyUserInfo(params)
       .then(() => {
-        update({
-          ...user,
-          ...params,
-        });
+        getLoggedUserInfo().then(update);

Review Comment:
   @DanielAuerX Thanks for the feedback, it made us realise that there is a bit of an issue with the backend here for errors as well. Maybe just adjust the error handling on the backend. 
   
   https://github.com/apache/answer/blob/3f1ed50f6776452c11b6ffdbdc767cd1887d629b/internal/service/uploader/upload.go#L152
   
   ```go
   // There should be a 404 error here
   return "", errors.NotFound(reason.UnknownError).WithError(err)
   ```
   
   https://github.com/apache/answer/blob/3f1ed50f6776452c11b6ffdbdc767cd1887d629b/internal/base/middleware/avatar.go#L62-L68
   
   ```go
   filePath, err = am.uploaderService.AvatarThumbFile(ctx, filename, size)
   if err != nil {
   	log.Error(err)
   	ctx.AbortWithStatus(http.StatusNotFound)
   	// This should not be continued here, but should be returned directly, because the file no longer exists.
   	return
   }
   ```
   
   



-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix file record and delete files (branding and avatar) [answer]

Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars commented on code in PR #1335:
URL: https://github.com/apache/answer/pull/1335#discussion_r2101497814


##########
ui/src/pages/Users/Settings/Profile/index.tsx:
##########
@@ -241,10 +241,7 @@ const Index: React.FC = () => {
 
     modifyUserInfo(params)
       .then(() => {
-        update({
-          ...user,
-          ...params,
-        });
+        getLoggedUserInfo().then(update);

Review Comment:
   @DanielAuerX So, let's just remove the commit and [adjust the error handling on the backend](https://github.com/apache/answer/pull/1335#discussion_r2096796582). 



-- 
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: commits-unsubscribe@answer.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org