DRAFT Add Standard Query Parameters support
AbandonedPublic

Authored by barchiesi on Mar 21 2019, 6:25 PM.

Details

Reviewers
dvratil
Summary

The Drive API allows setting certain standard query parameters, valid for all invocations (see Standard Query Parameters). Some of these are useful (setting what fields a request needs allows increasing performance) while others would be useless in a library (prettyPrint comes to mind, we de-serialize directly into objects).

This patch adds support for the fields query parameter in Job and sets up About to use it. Before proceeding with the other jobs/entities, is this the correct approach? Is the functionality something we want in LibKGAPI?

Test Plan

AboutFetchJobTest has been updated to test a fetch with a limited subset of fields.

Diff Detail

Branch
wip
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 11201
Build 11219: arc lint + arc unit
barchiesi created this revision.Mar 21 2019, 6:25 PM
Restricted Application added a project: KDE PIM. · View Herald TranscriptMar 21 2019, 6:25 PM
Restricted Application added a subscriber: kde-pim. · View Herald Transcript
barchiesi requested review of this revision.Mar 21 2019, 6:25 PM
dvratil requested changes to this revision.Mar 22 2019, 1:30 PM

Nice! I think this is a great thing to have in libkgapi, thanks for looking into this.

Some API design related comments below, but the approach is generally OK.

autotests/drive/aboutfetchjobtest.cpp
84

Should we maybe provide the fields as string constants in the relevant job APIs (or elsewhere)?

src/core/job.cpp
433

Coding style: Type &var instead of Type& var

src/core/job.h
188

IMO should be a QStringList to allow usage like

job->setFields({Field1, Field2, Field3});

Same for the getter. We can concatenate the fields just before serializing them into the query ourselves, but the API will be nicer for users.

193

Extra Am ?

202

Use QVector instead of a QList, please. You can drop the space between > >, too. C++11 fixed the grammar, so it's not misparsed as a streaming operator anymore.

Also, create a custom struct with properly named members (query, value, maybe?) instead of using a QPair. I know the QUrlQuery API uses that, but let's not be lazy just because Qt is :-)

src/drive/driveservice.cpp
43 ↗(On Diff #54498)

Pass complex types as const &. It doesn't make much difference since Qt containers are implicitly shared, but it's a convention in Qt-based code.

This revision now requires changes to proceed.Mar 22 2019, 1:30 PM

Btw regarding the prettyPrint param, should we set it to false, maybe? It's true by default, so disabling it could further improve performance and lower the bandwidth.

barchiesi added inline comments.Mar 22 2019, 5:19 PM
autotests/drive/aboutfetchjobtest.cpp
84

Each entity has its own fields therefore I believe each should have its own set of constants. Does that sound right?

dvratil added inline comments.Mar 22 2019, 5:59 PM
autotests/drive/aboutfetchjobtest.cpp
84

If the field names are bound to individual entities rather than jobs, then putting it into the entities makes sense.

barchiesi updated this revision to Diff 54586.Mar 22 2019, 11:01 PM

I noticed most jobs set the Authorization header on their own so perhaps a standard request builder is needed. I added Job::authorizedRequest with encapsulates this and also adds standard query parameters.

Added all field names as constants to the About class and disabled pretty by default.

dvratil requested changes to this revision.Mar 28 2019, 11:57 AM

Sorry, I forgot to do a second round of review.

src/core/job.cpp
436

prettyPrint doesn't need to be (shouldn't be!) a reference.

472

Do you maybe need to adjust /all/ tests, now to reflect this?

src/drive/about.h
224

I'm not sure how I feel about this barrage of members, if nothing else this will pollute auto-completer in the IDEs :-)

What do you think about this?

class About {
    ....
    struct Fields {
        static const QString AdditionalRoleInfo;
       ...
    };
};

Then the usage would be About::Fields::AdditionalRoleInfo, which feels cleaner and won't pollute About itself that much.

This revision now requires changes to proceed.Mar 28 2019, 11:57 AM
barchiesi updated this revision to Diff 56900.EditedApr 24 2019, 3:05 PM

Ok so I updated most test urls to reflect the prettyPrint change. I'm not sure what is left out but I will soon find out.
I also refactored File and FileFetchJob so the setFields is centralized. This will require that dependent projects rewrite their FileFetchJob::setFields() invocations, not sure how much of a negative impact that is...

barchiesi updated this revision to Diff 56936.Apr 25 2019, 12:17 AM

So I ditched Job::authorizedRequest() and now apply auth headers and standard params directly in Job::Private::_k_dispatchTimeout(). Basically I realized that perhaps some kind of jobs don't need the prettyPrint param set to false (no output or the cost is greater than the gain? delete methods maybe?) and in these cases I want to be able to remove the query param in the dispatchRequest implementation (eg. DeleteJob::dispatchRequest).
Does the above seem reasonable?
I also fixed up a little FileLogger so it produces a cleaner output.

barchiesi updated this revision to Diff 56937.Apr 25 2019, 12:35 AM

Changed DeleteJob and ContactModifyJob to demonstrate prettyPrint overriding.

dvratil requested changes to this revision.Apr 28 2019, 3:56 PM

WOW, this is huge! Big thanks.

I think generally it could go in like it is, but since this review ended up doing three changes, would you mind to split it into three reviews? One for the authorization header, one for the pretty-print and one for the custom fields - mostly to just avoid having one massive git commit touching everything.

src/drive/about.cpp
364

Coding style: spaces around = (here and everywhere below)

This revision now requires changes to proceed.Apr 28 2019, 3:56 PM

Have all the changes from this draft been submitted? If so, can this be abandoned? :)

barchiesi abandoned this revision.May 19 2019, 4:59 PM

All changes have been covered by other differentials, this can be abandoned.