Skip to content

Preserve Existing MRU Computers when Saving #6110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ChihweiLHBird
Copy link
Contributor

@ChihweiLHBird ChihweiLHBird commented Feb 23, 2025

Fix: #6112
This is to fix an issue causing duplicated or lost of MRU computers when multiple windows (instances) of BOINC manager are saving the MRU list into the state.

@ChihweiLHBird ChihweiLHBird changed the title Merge the MRU computers list when saving Merge the MRU computers list with exitsting state when saving it into the state Feb 23, 2025
@AenBleidd AenBleidd added this to the Client/Manager 8.2.0 milestone Feb 23, 2025
@ChihweiLHBird ChihweiLHBird changed the title Merge the MRU computers list with exitsting state when saving it into the state Preserve Existing MRU Computers when Saving Feb 23, 2025
@ChihweiLHBird ChihweiLHBird marked this pull request as ready for review February 26, 2025 03:14
@AenBleidd AenBleidd requested a review from Copilot February 26, 2025 08:31
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

@ChihweiLHBird
Copy link
Contributor Author

Hi @AenBleidd, any idea about adding tests for this change? I took a look but didn't find a good point for adding test for this functionality of BOINC Manager.

@AenBleidd
Copy link
Member

We don't have tests for that, so I'll test that manually.

@AenBleidd AenBleidd self-assigned this Feb 26, 2025
@AenBleidd AenBleidd moved this to In Progress in Planning Feb 26, 2025
@AenBleidd
Copy link
Member

Ok, looks like this doesn't work as intended.
Here I have tested in on the local installation.

  1. Open BOINC Manager
  2. Open second instance of BOINC Manager (e.g. via boincmgr.exe -m) and connect to the same machine (e.g. setting localhost)
  3. Close second instance and the first instance
  4. Open regedit.exe
  5. Navigate to Computer\HKEY_CURRENT_USER\Software\Space Sciences Laboratory, U.C. Berkeley\BOINC Manager\ComputerMRU
  6. Add duplicate entry (In my case I had 0: localhost and I added 1: localhost)
  7. Open BOINC Manager
  8. Close BOINC Manager.
  9. Check that two duplicate values are still there (should be only one)

@AenBleidd AenBleidd marked this pull request as draft March 12, 2025 15:32
@ChihweiLHBird
Copy link
Contributor Author

@AenBleidd thanks for testing it!

I just realized the current purposed change only prevents new duplicated items from being set, but it won't clean up existing ones.

I will make a change to support the cleaning up, maybe later this week.

@ChihweiLHBird ChihweiLHBird force-pushed the zhiwei/merge-computer-mru-when-saving branch from ae71e0d to 7bf4a4f Compare April 7, 2025 05:14
@ChihweiLHBird ChihweiLHBird force-pushed the zhiwei/merge-computer-mru-when-saving branch from 7bf4a4f to a5bc23f Compare April 12, 2025 07:26
@ChihweiLHBird ChihweiLHBird marked this pull request as ready for review April 12, 2025 07:27
@ChihweiLHBird
Copy link
Contributor Author

ChihweiLHBird commented Apr 12, 2025

Hi @AenBleidd, I think de-duplicating the computer list when loading the state would solve this, and it works in my local experiment. I just pushed the commit and the PR should be good for re-review now. Thank you!

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

clientgui/BOINCBaseFrame.cpp:782

  • [nitpick] Using the same variable 'iIndex' for both iterating over the config entries and for writing the updated list may reduce clarity; consider using a separate variable for the write loop to improve readability.
for (auto computer : existingComputers) {

@ChihweiLHBird ChihweiLHBird requested a review from Copilot April 12, 2025 07:30
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

@ChihweiLHBird ChihweiLHBird requested a review from Copilot April 12, 2025 07:31
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

clientgui/BOINCBaseFrame.cpp:773

  • [nitpick] Consider using a separate variable for iterating over the MRU list and for subsequent config entry numbering to avoid potential confusion with the reused iIndex variable.
for (iIndex = 0; iIndex < m_aSelectedComputerMRU.GetCount(); iIndex++) {

clientgui/BOINCBaseFrame.cpp:782

  • [nitpick] Consider iterating by const reference (e.g., 'for (const auto& computer : existingComputers) {') to improve readability and efficiency.
for (auto computer : existingComputers) {

@ChihweiLHBird ChihweiLHBird requested a review from Copilot April 12, 2025 07:42
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

@ChihweiLHBird
Copy link
Contributor Author

Couldn't understand why the check failed... is it a bug in the check itself?

@ChihweiLHBird ChihweiLHBird force-pushed the zhiwei/merge-computer-mru-when-saving branch from 5c04066 to 39d74a3 Compare April 21, 2025 22:09
@ChihweiLHBird ChihweiLHBird force-pushed the zhiwei/merge-computer-mru-when-saving branch from 39d74a3 to 67ac17e Compare April 21, 2025 22:14
@ChihweiLHBird ChihweiLHBird requested a review from Copilot April 21, 2025 22:14
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue (#6112) that caused duplicated or lost MRU computers when multiple BOINC Manager windows concurrently saved the MRU list. Key changes include:

  • Using size_t for index variables for better type-safety.
  • Retrieving existing computer entries from the config before overwriting.
  • Writing back non-duplicated entries and cleaning up extra config entries.
Comments suppressed due to low confidence (2)

clientgui/BOINCBaseFrame.cpp:763

  • [nitpick] Reusing 'iIndex' for both reading existing computers and writing the MRU list may be confusing for future maintainers. Consider using separate variables or clearly reinitializing 'iIndex' between these sections to improve clarity.
iIndex = 0;

clientgui/BOINCBaseFrame.cpp:790

  • [nitpick] The reuse of 'iIndex' here to remove remaining config entries relies on its previous value from the MRU writing loop. Consider adding an inline comment clarifying this intent to aid future maintenance.
strBuffer.Printf(wxT("%zu"), iIndex);

Signed-off-by: Vitalii Koshura <[email protected]>
@AenBleidd AenBleidd requested a review from Copilot May 25, 2025 01:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates how the MRU (Most Recently Used) computer list is saved and restored so that entries added by other running BOINC Manager windows are preserved rather than duplicated or dropped.

  • Changed MRU index variables to size_t and introduced existingComputers to merge saved entries across instances
  • In SaveState(), reads all existing entries before writing the current MRU list, appends any new external entries, then removes stale keys
  • In RestoreState(), prevents adding duplicates when rebuilding the in-memory MRU list
Comments suppressed due to low confidence (2)

clientgui/BOINCBaseFrame.cpp:733

  • [nitpick] The variable iIndex is used for multiple distinct loops (reading, writing, deleting). Consider renaming to readIndex, writeIndex, and deleteIndex to improve readability.
size_t          iIndex;

clientgui/BOINCBaseFrame.cpp:773

  • This complex merge logic would benefit from dedicated unit or integration tests to ensure that MRU entries are correctly preserved and merged when multiple manager instances save concurrently.
for (iIndex = 0; iIndex < m_aSelectedComputerMRU.GetCount(); iIndex++) {

Comment on lines +764 to 779
strBuffer.Printf(wxT("%zu"), iIndex);
while (pConfig->Exists(strBuffer)) {
wxString computer = pConfig->Read(strBuffer, wxEmptyString);
if (computer != wxEmptyString && existingComputers.Index(computer) == wxNOT_FOUND) {
existingComputers.Add(computer);
}
strBuffer.Printf(wxT("%zu"), ++iIndex);
}

for (iIndex = 0; iIndex < m_aSelectedComputerMRU.GetCount(); iIndex++) {
strBuffer.Printf(wxT("%zu"), iIndex);
pConfig->Write(
strBuffer,
m_aSelectedComputerMRU.Item(iIndex)
);
}
Copy link
Preview

Copilot AI May 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The pattern for iterating over numeric keys and reading entries is repeated. Extract this into a helper function to reduce duplication and make the logic clearer.

Suggested change
strBuffer.Printf(wxT("%zu"), iIndex);
while (pConfig->Exists(strBuffer)) {
wxString computer = pConfig->Read(strBuffer, wxEmptyString);
if (computer != wxEmptyString && existingComputers.Index(computer) == wxNOT_FOUND) {
existingComputers.Add(computer);
}
strBuffer.Printf(wxT("%zu"), ++iIndex);
}
for (iIndex = 0; iIndex < m_aSelectedComputerMRU.GetCount(); iIndex++) {
strBuffer.Printf(wxT("%zu"), iIndex);
pConfig->Write(
strBuffer,
m_aSelectedComputerMRU.Item(iIndex)
);
}
IterateNumericKeys(pConfig, wxT(""), [&](const wxString& key) {
wxString computer = pConfig->Read(key, wxEmptyString);
if (computer != wxEmptyString && existingComputers.Index(computer) == wxNOT_FOUND) {
existingComputers.Add(computer);
}
});
IterateNumericKeys(pConfig, wxT(""), [&](const wxString& key, size_t index) {
pConfig->Write(
key,
m_aSelectedComputerMRU.Item(index)
);
});

Copilot uses AI. Check for mistakes.

strBuffer.Printf(wxT("%zu"), iIndex);
while (pConfig->Exists(strBuffer)) {
wxString computer = pConfig->Read(strBuffer, wxEmptyString);
if (computer != wxEmptyString && existingComputers.Index(computer) == wxNOT_FOUND) {
Copy link
Preview

Copilot AI May 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Searching existingComputers with Index() is O(n) for each lookup. If the MRU list grows large, consider using a hash-based container (e.g., std::unordered_set) for faster membership checks.

Copilot uses AI. Check for mistakes.

Copy link

codecov bot commented May 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 11.93%. Comparing base (5f3e2ee) to head (a9d2077).
Report is 121 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6110      +/-   ##
============================================
- Coverage     11.94%   11.93%   -0.01%     
  Complexity     1068     1068              
============================================
  Files           278      278              
  Lines         36967    36985      +18     
  Branches       8541     8544       +3     
============================================
  Hits           4416     4416              
- Misses        32150    32168      +18     
  Partials        401      401              

see 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AenBleidd AenBleidd merged commit 073b25c into BOINC:master May 25, 2025
176 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Merged in Client/Manager May 25, 2025
@ChihweiLHBird ChihweiLHBird deleted the zhiwei/merge-computer-mru-when-saving branch May 25, 2025 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Merged
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Duplicated or lost hostname in the most recently use remote computers list in BOINC manager
2 participants