Hi, everyone, welcome back.
This is the part two of building dug it up job CPA client in this lecture.
What we are going to do is we are going to announce this use case to invoke the GitHub jobs API for
multiple page numbers at the same time for that purpose.
What I'm going to do is I'm going to create a function.
It's going to be public, and this function is going to return the same runtime, which is a list of
GitHub position.
And the function name is going to be invoke GitHub jobs API using multiple page numbers.
So the input to this function is going to be a little different from the input to this function to the
string description is going to be the same because we are still going to receive the description that
we want to search for.
And number two argument is going to be the list of page numbers are I'm going to have that as a first
argument.
So it's going to be.
List of integers.
And there you go.
So now we have this ready for now, let's have the return values now.
We will come back and revisit that in a bit.
Now, the ideas, we are going to iterate through this list and then invoke the good jobs API for each
and every page number in this list.
So let's take that.
So it's going to be page numbers, dot stream.
So we are going to stream on it and then we are going to call the map function to invoke the good jobs
API for each and every value in the page number.
So what we are going to do, we are going to get the page number in this one.
Right.
And after that we are going to invoke the function.
The function name is going to be this one.
After that, we are going to participate in a book followed by that we are going to pass the description.
So what this is going to read and this is going to return a list of giddap position, now, what we
are going to use, we are going to use a flat map function to flatten that list to an individual object.
So it's going to be a flat map.
Flat map is going to give you.
First thing is we need to access the list of Gitter positions.
I'm going to give a name like this.
And after that, what we are going to do, I'm going to do the guitar positions.
It's going to be, you know, questions have one additional lamda that remove that and then do the scream.
So if you do that, this is going to flatten the list to one individual objects.
And after that, we are going to do the collecting.
So collectors, basically collectors that told us that he got.
We have this very intelligent is giving me some recommendation, let's see what the recommendation is,
replace the LAMDA with the reference.
I'm going to do this.
There you go.
We have the functionality completely ready.
Now, what I'm going to do, I'm going to assign a.
Variable for this result, there you go, and we are getting the get a portion and then I'm going to
return the GitHub positions.
Now what I'm going to do, I want to calculate the time it took to perform the overall calculation of
invoking the good jobs API for each and every page number in the list.
So I'm going to use the start more function that we have as part of the annual Riggall.
So I'm just importing the static method and I'm going to spend the time taken to comminuted time taken.
So we are calculating or measuring the total time we took in order to perform the overall computation.
Now, the next step, as we all know, I'm going to write a test case for this one.
We have the GitHub jobs claim already available.
Let's go there.
There you go.
This is the this case.
I'm going to put this in a side-by-side view.
There you go.
Now, what we are going to do, I'm going to copy the same test, put it here.
But instead of invoking the GitHub dropship with page number, I'm going to do this.
There you go, but the input is going to be a little right.
I'm going to build a list, so it's going to be a list of integer.
So it's going to be on the list.
And I'm going to use a list of function to create a variable list that's going to list off one, two,
three.
So I want to just invoke this function for three page numbers.
And what we are going to do, we are going to invoke the function and the first parameter is going to
be page, name, list.
There you go, we that and then put that I'm going to pass is a Jawa.
Now what I'm going to do, I'm going to run this function, let it go.
The task is just getting launched for Java.
And as you can see, the first call is being made, and once the response is received, we are going
to make the call for the second one that he got.
So we made three calls and the total time, if you take a look at the total time, it took us seven
to seven, six.
So overall, it took seven seconds to complete the overall transaction.
This is not really great.
The reason why it took seven, 2006 is because it is waiting for the response for each and every page
in this iteration saying, here it is, we got a little bit I'm going to close this case in here.
What we are doing is we are iterating through the stream and then you are getting the page number one
first and you are working the API and you're waiting for the results and then you're walking the page
number two and then you are invoking the API.
We're waiting for the result.
And then for the page number three, you do the same thing.
It's going in a sequential and synchronous and blocking manner.
That's one of the reasons why it took seven seconds to complete the overall transaction.
Now, in the next lecture, I'm going to show you the technique to use computable future in here to
improve the overall performance.
These kind of skills are pretty common if you are building applications using Microsoft services, architecture
and the performance that we saw, that is not something which is acceptable when you are building applications,
which requires faster performance.
So in the next lecture, I'm going to show you the technique using complete future to improve the overall
performance of this API.
This marks the end of this lecture.
Thank you for watching.