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
Fixes #724: Push search data to server using api/push.json endpoint of server #753
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please look why Travis is failing.
Codecov Report
@@ Coverage Diff @@
## development #753 +/- ##
===============================================
+ Coverage 51.66% 51.67% +0.01%
===============================================
Files 99 100 +1
Lines 2499 2512 +13
Branches 278 278
===============================================
+ Hits 1291 1298 +7
- Misses 1180 1187 +7
+ Partials 28 27 -1
Continue to review full report at Codecov.
|
@praveenojha33 I have fixed it, please review again. @singhpratyush @sudheesh001 Please review. It is made for pushing one status at a time for now. I am working to make it parallel using something like fork_join. But it will take sometime, till then it can be used to boost up server's data. Sending more than one post request with more than one status leads to server error for request. |
@simsausaurabh: What error were you facing with the request with multiple messages? Can you paste the cURL for the request that you were making? |
@singhpratyush I was facing server 503 error while making a request with multiple messages. Currently server is not returning results, so I am unable to provide that snapshot. I am making a post request from the created Push Service. Here: https://github.com/fossasia/loklak_search/pull/753/files#diff-06795d93ddaa297718495e8ade90d648 |
I have made a separate utility function, and kept the calling limited to only 1. Once I figure out in making multiple request parallelly, it will be increased to 20 (Either 2 at a time in one request which makes only 10 parallel post request, or 1 at a time which will increase the load to 20 times i.e. 20 parallel post request). Because sending more than 2 statuses in one post request is also stating 503 server error. |
@singhpratyush Please review |
src/app/services/push.service.ts
Outdated
'Accept': 'application/json', | ||
'cache-control': 'no-cache' | ||
}); | ||
if (data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusing. Please add conditionals to explain this.
src/app/services/push.service.ts
Outdated
'cache-control': 'no-cache' | ||
}); | ||
if (data) { | ||
const temp = '' + JSON.stringify(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes no sense to add ''
to a string, it remains the same.
src/app/services/push.service.ts
Outdated
if (JSON.parse(temp)['aggregations']) { | ||
const subTemp = temp.substr(0, temp.length - 19) + '}'; | ||
if (JSON.parse(subTemp)['statuses'][0]) { | ||
const metadata = '{"search_metadata":' + getMetadata(subTemp) + ',"statuses":'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what this is about but this is not the right way to generate JSON strings.
Something as simple as this should do -
const {metadata, statuses} = data;
const dataToSend = JSON.stringify({search_metadata: metadata, statuses});
src/app/services/push.service.ts
Outdated
const value = metadata + getStatuses(subTemp) + '}'; | ||
const body = new HttpParams() | ||
.set('data', value); | ||
this.http.post(jsonpUrl, body.toString(), {headers: headers}).subscribe(val => console.log(val)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to dispatch any actions with this event?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need an additional action for this, although we can create one. But what could it be used for? For stating a success on push? We can create one for it, but it would not be used as of now anywhere else. And we can not use already available SEARCH_COMPLETE_SUCCESS which do not favours this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am missing on any point, then please guide me to it.
import { HttpClientModule, HttpClient } from '@angular/common/http'; | ||
import { PushService } from './push.service'; | ||
|
||
describe('PushService', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests technically do not test anything significant.
How do you know that proper calls are made and functions are called accordingly? Please try to cover more cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to use already existing mock data inside shared/mocks/feedItem.mock.ts
, but there comes some issue with some of the parameters inside individual: search_metadata
, statuses
, and aggregations
. I tried to make it work out, but it is taking longer time than expected. Currently the simple test checks that push service is being created. I will add tests in later patches (Because many other parts need new tests since the project is upgraded, and the tests written earlier can't be taken as it is, I have to write new ones). I want to fix sidebar, newsTab issue firstly before this weekend. Hope that works?
@@ -118,6 +118,7 @@ export class ApiSearchEffects { | |||
), | |||
withLatestFrom(this.store$), | |||
map(([action, state]) => { | |||
this.pushService.postData(action['payload']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is otiose to push data to the backend when you are actually getting the data from the backend. It would already contain all the statuses in this case.
The push servlet is supposed to be used when we are fetching Tweets using Twitter API they may be new for the backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree it would be more helpful once we complete the twitter api support. But till then it could work I guess, after that we can just push the mapped data from twitter api i.e. the data extracted from twitter api mapped in format of api.loklak. I have made all other changes, and I will surely write the tests in further patches. Thanks @singhpratyush.
src/app/utils/push.ts
Outdated
@@ -0,0 +1,7 @@ | |||
export function getStatuses(data: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why you are jumping forth and back with object and JSON string. This can be made very simple. Just use JSON.stringify
when needed.
a393644
to
c40509f
Compare
@singhpratyush Please review. I will write test in further patches, since its taking longer time than expected and there are issues like newsTab and sidebar which needs to be fixed before this weekend. |
src/app/services/push.service.ts
Outdated
|
||
constructor( private http: HttpClient ) { } | ||
|
||
public postData(data: ApiResponse) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this method use some callback or return a promise? How will other parts of the code interact with the completion state of this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we do not need a call back or a return promise since we are not currently using the returned response apart from logging it on console.
But surely, we can return the response. It can be used to test the method/push service, and I would be adding it while writing test case for it.
6bf5769
to
cc4f8c8
Compare
@singhpratyush Please review. I am writing tests. I will be sending them frequently in further patches. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style issues are not leading for travis build to fail, not sure why.
Almost good to merge, please look at the comments.
src/app/services/push.service.ts
Outdated
}); | ||
// Extracting search_metadata and statuses | ||
// from the data obtained from search result. | ||
const {search_metadata, statuses} = data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using lowerCamelCase
, please be consistent.
Not sure why the build isn't failing for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But search_metadata
is the property inside data. It shows error removing/making it to lowerCameCase, since it would not be a know property of data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { statuses } = data;
const searchMetadata = data.search_metadata;
This becomes long, but consistency is maintained. We can't control search_metadata
in response, but we can control what we want to use as a variable.
src/app/services/push.service.ts
Outdated
// Making a Post request to api/push.json endpoint | ||
// of server with required header and data body. | ||
// Response Object is converted to PushApiResponse type. | ||
return this.http.post<PushApiResponse>(httpUrl, body, {headers: headers}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{headers}
would do.
@singhpratyush Please review. |
@singhpratyush Please review. |
@mariobehling Please review. |
Changes proposed in this pull request
Screenshots (if appropriate)
Link to live demo: http://pr-753-fossasia-loklaksearch.surge.sh
Closes #724