gitui icon indicating copy to clipboard operation
gitui copied to clipboard

Refactor AsyncTags

Open mvaneijk opened this issue 4 years ago • 11 comments

Hi @extrawurst, I thought it would be a good idea to push my preliminary solution because I have some questions.

  1. ~~I looked at the other 2 implementations of AsyncSingleJob, do you think the solution is the right direction?~~
  2. ~~Why is there a 3 second timer in the current get-tag code? It seems interlinked with the async code, but it doesn't appear in the AsyncSingleJob struct. Is it still needed?~~
  3. ~~It seems there is a regression that removes the commit messages in the tags list, is that on purpose? does it need fixing? can I fix it directly in this PR? (introduced with 0f896933) - ah, it seems an issue with tui or crossterm (maybe broken API?)~~

Implementation

  1. It took some effort, and it probably is very much obvious that my previous rust experience is close to 0, but I think I have build an (at least functional) refactor.
  2. I wanted to preserve the "unchanged" notification functionality used in AsyncTags, so I moved it over to AsyncJob

Review

@extrawurst, can you perform a review and give me some guidance on what parts to improve?

Documentation

This Pull Request fixes/closes #757.

It changes the following:

  • Refactor AsyncTags to AsyncTagsJob
  • ~~(Fix regression: missing commit messages in TagList?)~~

I followed the checklist:

  • n/a - refactor
  • [x] I ran make check without errors
  • [x] I tested the overall application
  • [x] I added an appropriate item to the changelog

mvaneijk avatar Aug 22 '21 20:08 mvaneijk

Hi @mvaneijk sorry for making you digg into this without having checked deeper myself. turns out the asyncjob abstraction was not good ending yet to allow you to do this in a nice way.

I pushed a few additions now:

  • run now returns a notification value we want to be sent out when the job finished, this way you can customise depending on notify
  • run takes a RunParams type as a param now which allows us to send intermediate updates out (this is needed to do stuff like the push/pull progress bar) (see in action here: https://github.com/extrawurst/gitui/issues/889#issuecomment-911879771)

I think this should provide everything you need. For the is_outdated and force stuff you can write a simple wrapper around AsyncSingleJob<YouTagsJob> that uses take_last, stores the last result and uses it to always be able to check whether the last result is outdated. I hope I make sense :D

extrawurst avatar Sep 02 '21 16:09 extrawurst

Hi @extrawurst, thanks for the effort. No worries, this is a good exercise for me to get acquainted with Rust.

Regarding the 'simple' wrapper. I will think of something. But I guess I probably end up creating another AsyncSingleJob for this wrapper/awaiter, because it can only compare the last_job hash after the tagsjob has finished. And the wrapper cannot be blocking while awaiting the result, hence should be an AsyncJob.

mvaneijk avatar Sep 02 '21 20:09 mvaneijk

hi @extrawurst, I don't know how to perform the hashcheck without changing the AsyncSingleJob code.

Situation

  1. What is needed, is a function that
    1. performs the hash of the result upon completion of the get_tags function.
    2. compares the hash to the last result stored in the queue
    3. sends the appropriate notification according to the hash comparison
  2. However, this function cannot be part of the AsyncJob, since the AsyncJob knows nothing about other AsyncJobs in the queue
  3. This function cannot be part of a synchronous wrapper, because it has to wait on the AsyncJob result before running the hash function, and we don't want it to block.
  4. This function cannot be part of an asynchronous wrapper (instantiating another AsyncSingleJob queue, because previous three points will recursively apply on the new instance.

I think there are 2 options

  1. Make it possible to run a function at AsyncSingleJob scope upon completion of the AsyncJob
  2. Make the last_result available for the current running AsyncJob.

Both need changing of the AsyncSingleJob code, what do you think?

~ edit: after some rethink, I guess option 1 makes the most sense. Probably a "send_notification" function as part of the AsyncJob trait that gets access to last_result. Sounds like a combination of the two :)

mvaneijk avatar Sep 05 '21 08:09 mvaneijk

The eagle has landed

I guess I've seen the light :)

@extrawurst, can you review it?

mvaneijk avatar Sep 05 '21 12:09 mvaneijk

The eagle has landed

I guess I've seen the light :)

haha that sounds great! ❤️

@extrawurst, can you review it?

I will, as soon as I am back from my vacation!

extrawurst avatar Sep 13 '21 20:09 extrawurst

I checked out the branch and played around in it and noticed the tags are not showing anymore in the log tab:

Screenshot 2021-10-06 at 11 17 13

master: Screenshot 2021-10-06 at 11 18 53

extrawurst avatar Oct 06 '21 09:10 extrawurst

Good catch, I will look into it.

mvaneijk avatar Oct 07 '21 18:10 mvaneijk

@mvaneijk are you still on this?

extrawurst avatar Nov 20 '21 12:11 extrawurst

I will try again today and let you know if I give up after that. I have a hard time debugging the issue,

mvaneijk avatar Nov 27 '21 13:11 mvaneijk

@extrawurst feel free to assign someone else to it. Maybe part or my PR can be reused, I feel that it is something small but I will probably have time again in the Christmas Holidays.

mvaneijk avatar Nov 28 '21 16:11 mvaneijk

putting into draft until picked up again

extrawurst avatar Sep 18 '22 13:09 extrawurst

This issue has been automatically marked as stale because it has not had any activity half a year. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 17 '24 15:03 stale[bot]