parse-community / Parse-Swift

The Swift SDK for Parse Platform (iOS, macOS, watchOS, tvOS, Linux, Android, Windows)
https://parseplatform.org
MIT License
308 stars 69 forks source link

feat: enable query caching by using GET instead of POST #386

Closed cbaker6 closed 2 years ago

cbaker6 commented 2 years ago

New Pull Request Checklist

Issue Description

All queries currently use POST requests, preventing the ability to leverage the cache policies available in the SDK.

Related issue: #382

Approach

Enable all queries to use GET requests by default so queries are cached. Developers can change the default request behavior for all queries by setting usingPostForQuery = true to not cache any of the queries. Setting usingPostForQuery = true can be useful when using the Swift SDK on the server-side as many developers will not want the server caching queries.

TODOs before merging

parse-github-assistant[bot] commented 2 years ago

Thanks for opening this pull request!

codecov[bot] commented 2 years ago

Codecov Report

Merging #386 (7e0c992) into main (7ba4f95) will decrease coverage by 0.52%. The diff coverage is 80.99%.

@@            Coverage Diff             @@
##             main     #386      +/-   ##
==========================================
- Coverage   89.66%   89.13%   -0.53%     
==========================================
  Files         155      156       +1     
  Lines       14125    14528     +403     
==========================================
+ Hits        12665    12950     +285     
- Misses       1460     1578     +118     
Impacted Files Coverage Δ
Sources/ParseSwift/API/API.swift 99.35% <ø> (-0.03%) :arrow_down:
...urces/ParseSwift/API/API+NonParseBodyCommand.swift 81.09% <77.77%> (-0.44%) :arrow_down:
Sources/ParseSwift/Types/Query.swift 87.47% <80.72%> (-7.67%) :arrow_down:
Sources/ParseSwift/API/API+Command.swift 89.21% <100.00%> (ø)
Sources/ParseSwift/Extensions/Dictionary.swift 100.00% <100.00%> (ø)
Sources/ParseSwift/Parse.swift 98.79% <100.00%> (+0.02%) :arrow_up:
Sources/ParseSwift/Objects/ParseObject.swift 84.80% <0.00%> (-0.31%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

cbaker6 commented 2 years ago

@aliasad106 you can try out this branch for query cache. It should work without any changes needed on your end as long as you didn't change the default cache policy of the SDK. I've tested it with some of the query code in Playgrounds and it seems to work.

I still need to add test cases to ensure this doesn't break in the future and to fix the code coverage.