Skip to content

refactor(database): Add types to several classes and utility methods #66

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

Merged
merged 1 commit into from
Jul 8, 2017

Conversation

jsayol
Copy link
Contributor

@jsayol jsayol commented Jun 17, 2017

Refactoring of several classes and utility methods to add proper types and annotations

return [str];
}

var dataSegs = [];
for (var c = 0; c < str.length; c += segsize) {
if (c + segsize > str) {
Copy link
Contributor Author

@jsayol jsayol Jun 17, 2017

Choose a reason for hiding this comment

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

This condition would never be true since it's comparing a number with a string. It was probably meant to say
if (c + segsize > str.length) {

This has probably gone undetected for a while since it didn't cause any problems anyway. According to MDN for substring: If either argument is greater than stringName.length, it is treated as if it were stringName.length.

We might as well remove the condition altogether?

SessionStorage.set('logging_enabled', true);
}
else if (typeof logger === 'function') {
logger = logger;
Copy link
Contributor Author

@jsayol jsayol Jun 17, 2017

Choose a reason for hiding this comment

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

There was something weird here between the module-wide logger variable and the parameter passed to the enableLogging() function.

Edit: I just checked the original JS code and the module-wide variable was fb.core.util.logger, so that explains it. Make sure to review these changes with special care anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great catch on this. This is, as you pointed out, a bug from migration.

newParams.endNameSet_ = true;
newParams.indexEndName_ = key;
} else {
newParams.startEndSet_ = false;
Copy link
Contributor Author

@jsayol jsayol Jun 17, 2017

Choose a reason for hiding this comment

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

startEndSet_ doesn't exists in this class. I'm 99.9% sure this was meant to say endNameSet_, but double-check just in case.

Edit: the same mistake is present in the current JS code. It's probably a good idea to check whether fixing this might somehow introduce a breaking change, in case other parts of the code are unknowingly relying on the current behavior.

Edit 2: nah, it's safe to make this change. The way it currently works, calling QueryParams#endAt() would fail to set endNameSet_ to false when called without a key name, but it was already initialized as false anyway. Subsequent calls to endAt() are not allowed by Query, so it never changes after that.

@jshcrowthe
Copy link
Contributor

I'm going to try and dig into this in the next couple of days. I want to get the test harness in a place where it is available first. Initial look is good though!

@jsayol
Copy link
Contributor Author

jsayol commented Jun 20, 2017

Sure @jshcrowthe, no hurry!

I was taking a look at the new tests and I realized it will be necessary to make a few changes to some of them if this PR is merged, specially when using classes like SortedMap, LLRBNode, ImmutableTree, etc, since I added generic types.

Let me know when that PR is merged and I'll update this one with any necessary changes, ok?

@jshcrowthe jshcrowthe force-pushed the ts-database/add-new-impl branch from 7efa1b0 to 2f6a406 Compare June 20, 2017 22:26
@jsayol jsayol force-pushed the ts-database-changes branch 6 times, most recently from d0c40aa to 7eb6213 Compare June 22, 2017 11:05
@@ -45,7 +47,6 @@ export class PacketReceiver {
}
if (this.currentResponseNum === this.closeAfterResponse) {
if (this.onClose) {
clearTimeout(this.onClose);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this clearTimeout since this.onClose is a function. Probably left over from a previous change.

@jsayol
Copy link
Contributor Author

jsayol commented Jun 22, 2017

I had to force-push some changes to the first commit. If you already pulled it earlier then make sure to pull the latest version.

Copy link
Contributor

@jshcrowthe jshcrowthe left a comment

Choose a reason for hiding this comment

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

I have gone through this and it all looks pretty good. There are some stylistic differences here but I plan on hitting the whole project with the prettier hammer here after this PR is merged so I'm going to ignore that for now.

if (repoInfo.host !== (<RepoInfo>(<any>this.repo_).repoInfo_).host) {
fatal(apiName + ': Host name does not match the current database: ' +
'(found ' + repoInfo.host + ' but expected ' +
(<RepoInfo>(<any>this.repo_).repoInfo_).host + ')');
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed there is a couple places in this file where we do the <T> casting. We currently aren't using TSX but if we wanted to we would probably need to migrate these to do as casting.

This is true for all instances of this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@jshcrowthe
Copy link
Contributor

The test harness fails on this with a slew of errors. Please point this to ts-database/final and as we are able to get the tests PR in we can fix these issues.

@jsayol
Copy link
Contributor Author

jsayol commented Jun 27, 2017

Yeah, that's probably because of the generic types that I mentioned. I'll look into it.

@jsayol
Copy link
Contributor Author

jsayol commented Jun 27, 2017

If I point this PR to the ts-database/final branch then it will also bring all the commits from PR #62, since this one is built on top of those changes. It might be a bit of a mess.

Should I do it anyway and then rebase later when that PR is merged?

@jsayol jsayol force-pushed the ts-database-changes branch 3 times, most recently from b128848 to 3b95509 Compare June 27, 2017 22:06
@jsayol
Copy link
Contributor Author

jsayol commented Jun 28, 2017

Just for reference, this is the result of my build and these numbers are after minification:

File Parsed Size Gzip Size
firebase-app.js 17.94 KB 5.97 KB
firebase-auth.js 135.47 KB 42.17 KB
firebase-database.js 1.29 MB 370.1 KB
firebase-messaging.js 24.93 KB 6.59 KB
firebase-storage.js 54.02 KB 13.4 KB
firebase.js 1.51 MB 436.35 KB

So clearly something's amiss. Besides that, I just merged my changes into the ts-database/migrate-test-harness branch locally and I can't get the tests to run because of a missing file:

[23:43:01] 'runAllKarmaTests' errored after 9.86 s
[23:43:01] Error: Unable to resolve module [../../config/project.json] from [/home/josep/projects/firebase-js-sdk/tests/database/helpers/util.js]

I think you're right, I probably messed up a merge at some point. I'll see if I can sort this out tomorrow, thanks for the patience :)

@jsayol jsayol force-pushed the ts-database-changes branch 3 times, most recently from 8406db5 to d9fea62 Compare June 29, 2017 00:54
@jsayol
Copy link
Contributor Author

jsayol commented Jun 29, 2017

Ok, I've solved all the merge issues. Sorry for all the noise about this. There's a handful of tests failing but I'll look into that tomorrow.

@jsayol jsayol force-pushed the ts-database-changes branch from d9fea62 to 322c54a Compare June 29, 2017 08:11
@jsayol
Copy link
Contributor Author

jsayol commented Jun 29, 2017

Only 2 tests are failing on my end:

  • Connection -> disconnect old session on new connection: It's marked as flaky in the comments, so I assume it's known to fail some times?
  • Transaction Tests -> Transaction aborts after 25 retries.: It's actually working as expected (it does abort after 25 retries) but it's erroring due to the 2000ms timeout, while in my test it takes about 3200ms on average to complete.

@jshcrowthe
Copy link
Contributor

jshcrowthe commented Jun 29, 2017

@jsayol perfect, as part of the review for #71 we are adding a global timeout of 5000ms to the tests. So that should hopefully solve your issue. Going forward we need to find a way to fix the coupling to the prod database for these tests. But that can be a separate issue. That would help solve some of the volatility in these tests.

In addition, it seems I forgot to skip the test in the Node test setup. I have skipped the test and pushed it to ts-database/migrate-test-harness.

@jshcrowthe
Copy link
Contributor

Hey @jsayol we have gotten all of the PR's merged, if you'll please rebase we can get this merged.

@jshcrowthe jshcrowthe changed the base branch from ts-database/final to master July 6, 2017 22:14
@jshcrowthe
Copy link
Contributor

I have pointed this PR to the master branch as we have merged #72

@jsayol
Copy link
Contributor Author

jsayol commented Jul 6, 2017

if you'll please rebase we can get this merged

Sure, I'll try to get around to it this weekend.

@jsayol jsayol force-pushed the ts-database-changes branch 2 times, most recently from a92520a to 4d30da1 Compare July 8, 2017 09:38
* refactor(database): Several classes and utility methods

* WIP: fix tests with recent type changes

* refactor(database): Type casting format for TSX support

* refactor(database): Add 'noImplicitAny' support
  Adds support for the 'noImplicitAny' Typescript compiler option to the database implementation.
@jsayol jsayol force-pushed the ts-database-changes branch from 4d30da1 to eca9bdd Compare July 8, 2017 09:50
@jsayol
Copy link
Contributor Author

jsayol commented Jul 8, 2017

@jshcrowthe done.

@jsayol jsayol changed the title refactor(database): several classes and utility methods refactor(database): Add types to several classes and utility methods Jul 8, 2017
Copy link
Contributor

@jshcrowthe jshcrowthe left a comment

Choose a reason for hiding this comment

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

Nice work here @jsayol! I want to get #94 and #90 merged before the release next week. That should get us to a nice working state for the database code.

SessionStorage.set('logging_enabled', true);
}
else if (typeof logger === 'function') {
logger = logger;
Copy link
Contributor

Choose a reason for hiding this comment

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

Great catch on this. This is, as you pointed out, a bug from migration.

@jshcrowthe
Copy link
Contributor

I have run tests locally and they all pass, Travis-CI seems to have hung, so I am going to merge this.

@jshcrowthe jshcrowthe merged commit 00f9c37 into firebase:master Jul 8, 2017
@jsayol
Copy link
Contributor Author

jsayol commented Jul 8, 2017

I want to get #94 and #90 merged before the release next week.

Nice! I'll make sure to get #94 ready by then.

@jsayol jsayol deleted the ts-database-changes branch July 13, 2017 07:20
@firebase firebase locked and limited conversation to collaborators Oct 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants