Skip to content

Updated deleteAll() method to delete all searches instead of 10(#2181) #2185

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
merged 4 commits into from
Dec 20, 2018

Conversation

cypherop
Copy link
Contributor

Fixes #2181 Clearing recent searches only removes last 10

What changes did you make and why?
Some minor changes in deleteAll() method. Now it deletes all the searches instead of just 10.

Tested on Motorola Moto G5 plus with API level 24.

@codecov-io
Copy link

codecov-io commented Dec 20, 2018

Codecov Report

Merging #2185 into master will increase coverage by 0.05%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2185      +/-   ##
=========================================
+ Coverage    5.72%   5.77%   +0.05%     
=========================================
  Files         231     231              
  Lines       11587   11604      +17     
  Branches     1078    1079       +1     
=========================================
+ Hits          663     670       +7     
- Misses      10869   10878       +9     
- Partials       55      56       +1
Impacted Files Coverage Δ
...mons/explore/recentsearches/RecentSearchesDao.java 0% <0%> (ø) ⬆️
...explore/recentsearches/RecentSearchesFragment.java 0% <0%> (ø) ⬆️
.../java/fr/free/nrw/commons/nearby/NearbyPlaces.java 0% <0%> (ø) ⬆️
...ain/java/fr/free/nrw/commons/nearby/Sitelinks.java 0% <0%> (ø) ⬆️
...w/commons/category/CategoryImagesListFragment.java 0% <0%> (ø) ⬆️
...r/free/nrw/commons/contributions/MainActivity.java 0% <0%> (ø) ⬆️
...ava/fr/free/nrw/commons/nearby/NearbyFragment.java 0% <0%> (ø) ⬆️
.../java/fr/free/nrw/commons/nearby/DirectUpload.java 0% <0%> (ø) ⬆️
.../fr/free/nrw/commons/nearby/NearbyMapFragment.java 0% <0%> (ø) ⬆️
...rc/main/java/fr/free/nrw/commons/nearby/Place.java 0% <0%> (ø) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24a76b1...d9c88a0. Read the comment docs.

@domdomegg domdomegg self-requested a review December 20, 2018 12:57
Copy link
Member

@domdomegg domdomegg left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I'd recommend adding a null check and had a couple of tiny formatting niggles

db.delete(recentSearch.getContentUri(), null, null);
Timber.d("QUERY_NAME %s - query deleted", recentSearch.getQuery());
try {
cursor = db.query( RecentSearchesContentProvider.BASE_URI, Table.ALL_FIELDS,
Copy link
Member

Choose a reason for hiding this comment

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

Horizontal whitespace - GSG 4.6.2

Suggested change
cursor = db.query( RecentSearchesContentProvider.BASE_URI, Table.ALL_FIELDS,
cursor = db.query(RecentSearchesContentProvider.BASE_URI, Table.ALL_FIELDS,

It might be an idea to put each argument of db.query on a different line so it looks like

cursor = db.query(
    RecentSearchesContentProvider.BASE_URI,
    Table.ALL_FIELDS,
    null,
    new String[]{},
    Table.COLUMN_LAST_USED + " DESC"
);

} catch (RemoteException e) {
throw new RuntimeException(e);
} finally {
cursor.close();
Copy link
Member

Choose a reason for hiding this comment

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

Need to do a null check to avoid NPE i.e. if (cursor != null) {

try {
cursor = db.query( RecentSearchesContentProvider.BASE_URI, Table.ALL_FIELDS,
null, new String[]{}, Table.COLUMN_LAST_USED + " DESC");
while (cursor != null && cursor.moveToNext() ) {
Copy link
Member

Choose a reason for hiding this comment

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

Horizontal whitespace - GSG 4.6.2

Suggested change
while (cursor != null && cursor.moveToNext() ) {
while (cursor != null && cursor.moveToNext()) {

@domdomegg
Copy link
Member

Test results

Tested 2.9.0-debug-pr-2186~2cca3f7b5 on Galaxy Nexus (emulator) at API level 28

Automated tests pass

Does delete all recent searches in my testing, whereas in previous version can consistently recreate situations where it doesn't, so it fixes #2181.

@cypherop
Copy link
Contributor Author

Done:)

@domdomegg domdomegg self-requested a review December 20, 2018 15:39
@domdomegg
Copy link
Member

Will merge once Travis passes.

@domdomegg
Copy link
Member

Tested 2.9.0-debug-pr-2185~d9c88a0c on Galaxy Nexus (emulator) at API level 28

@domdomegg domdomegg merged commit a3b3373 into commons-app:master Dec 20, 2018
@cypherop cypherop deleted the fix#2181 branch December 20, 2018 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants