Skip to content

Conversation

@astansler
Copy link
Member

@astansler astansler commented Sep 20, 2017

  • Added common observable interface CommitObservable for boosting of a performance. All hashers now receive per commit info synchronously with pre calculated diff. In such way we can traverse commit graph and calculate diff only once per commit.
  • Moved facts logic to separate hasher.
  • Updated tests.
  • CodeLongevity doesn't prepared for this interface yet. (How can we do it?)

Codes of facts will be updated in other PR.

Copy link
Contributor

@asurkov asurkov left a comment

Choose a reason for hiding this comment

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

This is rather a rubber stamp review, since the patch is about moving existing code around, but the patch looks good from an architectural standpoint, and I believe it's a good step forward to bring our classes to a common base. Nevertheless I made some comments about moved code, but the comments may be handled in a followup if you want to (and if it needed for sure).

return try {
git.repository
.open(objectId).bytes.toString(Charset.defaultCharset())
.split('\n')
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably RawText text is safer here, '\n' and defaultCharset() might not work for each case. I realize that RawText might be doing the same under the hood, but at least we have someone to blame :)

Also inlined code works equally well: RawText(repo.open(objectId).getBytes()) and probably doesn't deserve own function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok.

})
init {
// Delete locally missing commits from server. If found at least one
// common commit then next commits are not deleted because hash of a
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose you meant "preceding commits" not "next commits"

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

val firstOverlapCommitRehash = findFirstOverlappingCommitRehash()
val deletedCommits = serverRepo.commits
.takeWhile { it.rehash != firstOverlapCommitRehash }
deleteCommitsOnServer(deletedCommits)
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 I would send a common found commit to a server and let the server to delete the following commits on its own

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's stay on current version of a protocol.

.map { commit -> commit.rehash }
.toHashSet()
return rehashes.firstOrNull { rehash ->
serverHistoryRehashes.contains(rehash)
Copy link
Contributor

Choose a reason for hiding this comment

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

You could simply traverse the commits looking for a rehash, and that'd be faster than putting everything into a hash set, because there are good chances to never traverse all commits, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm looking for first mapping of M(local) to N(server) commits not M(local) to 1. HashSet speed up the process.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I follow it, anyway, this code wasn't introduced by this pull request, so I guess I can revisit this part later and file followup issue if needed.

new.rehash != lastKnownCommit?.rehash
}
.filter { commit -> // Don't hash known.
knownCommits.isEmpty() || !knownCommits.contains(commit)
Copy link
Contributor

Choose a reason for hiding this comment

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

how could we reach it if we do takeWhile() until the lastKnownCommit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Server could miss some of the commits.

import java.nio.charset.Charset

object CommitObservable {
fun getObservable(git: Git, repo: Repo) = Observable
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a tautology to have CommitObservable.getObservable(). You may want to rename it to something like Commits.asObservable().

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed name to CommitCrawler, method name the same.

subscriber.onError(e)
}
subscriber.onComplete()
} // TODO(anatoly): Rewrite diff calculation in non-weird way.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a funny TODO item but not clear what exactly you want to do here. It's up to you to replace on something more descriptive or just ignore it.

val observable = CommitObservable.getObservable(git, serverRepo)
.publish()
CommitHasher(localRepo, serverRepo, api, rehashes)
.updateFromObservable(observable)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably rename the method to chainWith(observable) or JSish then(observable) or you could wrap that by some fancy interfaces like (names and code are sketchy)
interface Thenable {
then(commits: Observable);
};
FunHasher : Thenable {
override then(Observable)
}
and then
Commits.asObservalbe().
then(FunHasher).
then(CommitHasher)

Copy link

@yandzee yandzee left a comment

Choose a reason for hiding this comment

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

Looks good.

@astansler astansler merged commit efe0f5a into master Sep 25, 2017
@astansler astansler deleted the dev-observe branch October 2, 2017 12:24
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.

4 participants