Skip to content
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

Added git services, db caching and front end API changes #57

Open
wants to merge 12 commits into
base: v2
Choose a base branch
from

Conversation

asiyani
Copy link

@asiyani asiyani commented Jun 11, 2017

After merging this pull request Frontend will get data from backend DB.
Created Search API for front-end - (This one is not GraphQL) but some this for now just to use same front end without much modification.

Folders added.

  • gitUtility in server folder

    • gitService file will make external git API calls. 2 function we can use getUserDetails(login, token) & getStarredRepository(login, token, page = 1).
    • initialSeed.js for initail seeding data or udpating records in future.

created static method updateRepoWithStargazer in repositorySchema which we can use to update records in DB. this method will link Stargazer to Repos being updated.

  • Added repo APIs.
    • GET /api/repos/v1/search to search db with query parameter stargazer, language, page, per_page. this is to replicate current API we are doing to Github.
    • GET /api/repos/v1/updateRecord this is to start DB seeding.

Note:

We need to seed our DB for /api/repos/v1/search to work. To do that i have created simple call we can make from the browser (after login in).
Just go to http://localhost:3000/api/repos/v1/updateRecord. this will start seeding process and you will get logs on the terminal.
I am doing seeding for ALL starred records. some username got about 1K+ starred repos.I got about 11K repos documents in Repository collections. This process might take some time.

After seeding data front end will work as it is working now- just data will come from our db.
Since we are getting data from our server we can do following.
image

In the front-end, we need to change they way we do API calls when language is selected. Since now we can pass language as search parameter No need to filter that on the front-end.

Please let me know if any issue or what you guys think about this process of getting data.

@mubaris
Copy link
Owner

mubaris commented Jun 12, 2017

It didn't work until I called, /api/repos/v1/updateRecord manually. We need to find a method to overcome this.

Language selection is not working.

After a point application exits due to undefined response body

Copy link
Owner

@mubaris mubaris left a comment

Choose a reason for hiding this comment

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

It didn't work until I called, /api/repos/v1/updateRecord manually. We need to find a method to overcome this.

Language selection is not working.

After a point application exits due to undefined response body

@asiyani
Copy link
Author

asiyani commented Jun 12, 2017

Ya some of the language doesn't work becz dB doesn't have any repo for that language.
Which one you tried?does it work on previous front end?

@mubaris
Copy link
Owner

mubaris commented Jun 12, 2017

It's not working for Javascript. It was working previously.

@asiyani
Copy link
Author

asiyani commented Jun 12, 2017

I think its something to do with scroll, if you scroll down it starts doing API calls. Not sure why this is happening....

@mubaris
Copy link
Owner

mubaris commented Jun 12, 2017

It's working now. I don't know why it was happening.

@mubaris
Copy link
Owner

mubaris commented Jun 12, 2017

Username array isn't stored in DB. Is it?

@asiyani
Copy link
Author

asiyani commented Jun 12, 2017

No its just a file for now, but DB got all github info regarding those usernames.....

@mubaris
Copy link
Owner

mubaris commented Jun 12, 2017

If the user wants to add new username, it's not possible now.

@asiyani
Copy link
Author

asiyani commented Jun 12, 2017

Regarding adding username on end user request is not yet possible but I was Thinking if user wants to add username we will let him add that but only for him like temp data.
we will add it to our DB only if they it meet certain criteria. something like how many follower he got or count of repo. Otherwise our starzagers list will grow and we will loose quality.

}
console.log('isAuthenticated: No');
res.redirect('/user/login');
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to return 0 here?

Copy link
Author

Choose a reason for hiding this comment

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

This function will never reach return statement. either it will be redirected if not authenticated or next() will be called

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, so I think there's no reason to call a return in here then (dead code)

query.stargazersLogin = { $all: [req.query.stargazer] };
}
// Filter language depending on what selected.
if (req.query.language && req.query.language !== 'Any') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any && NoLanguage can live in their own file, something like constants/index.js

}
}
Repository.paginate(query,
{ page: parseInt(req.query.page, 10) || 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind changing this into:

{
 page: ...,
  limit: ....
}

Copy link
Author

Choose a reason for hiding this comment

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

I am sorry I didn't understand what you mean here...

Copy link
Owner

Choose a reason for hiding this comment

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

Beautify the code 😆

{ new: true, upsert: true },
(error, doc) => {
if (error) throw error;
//logger.debug(`Updated: ${stargazer}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove this commented code please? Unless it's really necessary for the future.


logger.level = 'info';

// logger.debug('Test Log Message', { anything: 'This is metadata' });
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented out code.

@@ -42,7 +42,7 @@ const selectLanguage = function selectLanguage(event) {
languageSelected = event.target.value;
content.innerHTML = '';
reqNo = Math.floor(Math.random() * 3) + 1;
projectsPerPage = (languageSelected == ANY_LANGUAGE) ? 2 : 100;
projectsPerPage = (languageSelected == ANY_LANGUAGE) ? 2 : 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can mode 10 into const MAX_PROJECTS = 10 or something similar.

innerContent += (entry.language != null) ? ` ${entry.language}` : '';
innerContent += ` (from ${userFormatter(username)})`;
// innerContent += ` (from ${userFormatter(username)})`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this commented out code here.

@@ -63,8 +68,12 @@ const getData = function getData() {
usersCurrentCall = 0;
callInProgress = true;
reqNo += 1;
if (reqNo > 10) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe use something more descriptive as const REQ_NUMBER???

USERNAMES.forEach((username) => {
const url = `https://api.github.com/users/${username}/starred?per_page=${projectsPerPage}&access_token=${accessToken}&page=${reqNo}`;
// const url = `https://api.github.com/users/${username}/starred?per_page=${projectsPerPage}&access_token=${accessToken}&page=${reqNo}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is commented code that I think it's not necessary, can you remove it?

@@ -1,4 +1,4 @@
let mongoose = require('mongoose');
const mongoose = require('mongoose');
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

if (repository.stargazersLogin.indexOf(stargazer) === -1) {
repository.stargazersLogin.push(stargazer);
}
Object.assign(repository, repo);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should better do Object.assign({}, repository, repo) to avoid any undesired mutation.

public_repos: Number,
public_gists: Number,
followers: Number,
}, { timestamps: { updatedAt: 'recordUpdated_at', createdAt: 'recordCreated_at' } });
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can write this object in multiple lines. A one liner is harder to read + the diff in the future might not be clear.


getUserDetails(login, token) {
if (token) {
headers = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see where headers is defined? Am I missing something here?

Copy link
Author

Choose a reason for hiding this comment

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

I have added header definition now...

return new Promise((resolve, reject) => {
logger.info('Calling api.github.com/users/user', { login });
request(options, (error, response, body) => {
if (!error && response.statusCode == 200) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Always use === instead of ==, using == can led to bugs most of times.

return new Promise((resolve, reject) => {
logger.info('Calling api.github.com/users/login/starred', { login, page });
request(options, (error, response, body) => {
if (!error && response.statusCode == 200) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment for ===

.eslintrc.json Outdated
@@ -16,6 +16,7 @@
"no-console": "off",
"func-names": "off",
"no-alert": "off",
"prefer-const": "off"
"prefer-const": ["error", {"destructuring": "all"}],
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really sure about this change, any specific reason for this update?

Copy link
Author

Choose a reason for hiding this comment

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

I have added that to warn us if let is used and we never resigned that variable.... {"destructuring": "all"} because of the following....

/*eslint prefer-const: ["error", {"destructuring": "all"}]*/
/*eslint-env es6*/

// 'b' is never reassigned, but all of `a` and `b` should not be const, so those are ignored.
let {a, b} = obj;
a = a + 1;

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should avoid this, if we mutate our data some weird bugs may arise.

@mubaris
Copy link
Owner

mubaris commented Jun 20, 2017

@alejandronanez @asiyani Status?

Copy link
Contributor

@alejandronanez alejandronanez left a comment

Choose a reason for hiding this comment

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

Enforce const { foo } = bar. Mutate our data is not good.

.eslintrc.json Outdated
@@ -16,6 +16,7 @@
"no-console": "off",
"func-names": "off",
"no-alert": "off",
"prefer-const": "off"
"prefer-const": ["error", {"destructuring": "all"}],
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should avoid this, if we mutate our data some weird bugs may arise.

@asiyani
Copy link
Author

asiyani commented Jun 20, 2017

Sorry guys have been busy for last few days. I have made all changes now.
Let me know if anything else needs changing.

@asiyani
Copy link
Author

asiyani commented Jun 30, 2017

Hi guys did you had time to review this?
Let me know if any issue

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.

None yet

3 participants