Skip to content

Feature/commit refactor#135

Merged
dlamoris merged 21 commits intodevelopfrom
feature/commitRefactor
Jan 28, 2021
Merged

Feature/commit refactor#135
dlamoris merged 21 commits intodevelopfrom
feature/commitRefactor

Conversation

@HuiJun
Copy link
Collaborator

@HuiJun HuiJun commented Jan 22, 2021

No description provided.

@HuiJun HuiJun requested a review from dlamoris January 22, 2021 01:39
Copy link
Collaborator

@dlamoris dlamoris left a comment

Choose a reason for hiding this comment

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

initial comments


public Optional<CommitJson> findById(String docId) {
return this.findById(getIndex(), docId);
public void index(BaseJson json, String commitId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i don't think this is needed - the caller should just give the right commitJson to index and not have to know about commitId overrides

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, removed


public void indexAll(Collection<? extends BaseJson> jsons) {
this.indexAll(getIndex(), jsons);
this.indexAll(getIndex(), associateCommits(jsons));
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should index commits 'as is' (see below for more), it shouldn't assume that indexing a collection of commit json means they're all related
also, the signature of this and index should probably change to CommitJson instead of BaseJson

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

}

public void index(BaseJson json) {
if (json.get(CommitJson.COMMITID).toString().isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think what should happen here (and in indexAll) is the breaking up of a single commit json into several if its arrays exceeds some threshold - so the caller can give a huge object, but because of the elasticsearch limits, only the elastic impl knows to break it up (similar to how the get knows to munge commit objects together and can return a huge object to the caller, the caller doesn't need to know about munging)

At the same time, if the caller already broke up the commits, this would still work as expected

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, but it might be done in a different way

}

public void deleteById(String commitId) {
this.deleteById(getIndex(), commitId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should delete all docs that have commitId, right now it treats commitId as the docId

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

public boolean existsById(String docId) {
return this.existsById(getIndex(), docId);
public boolean existsById(String commitId) {
return this.existsById(getIndex(), commitId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as delete ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


String commitId = params.get("commitId");
if (commitId != null && !commitId.isEmpty()) {
info.getCommitJson().setCommitId(commitId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should happen during the createCommit in the previous call, otherwise the elements getting updated will have the wrong commitId

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


public void initCommitJson(CommitJson cmjs, Instant now) {
cmjs.setId(UUID.randomUUID().toString());
cmjs.setCommitId(UUID.randomUUID().toString());
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should check if commitId is not set first, if it's not set, it should just be same as the id so it's still consistent with any existing paradigm

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

broken.add(currentCommitCopy);

}
this.indexAll(broken);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just fyi, this adds a property called "action" into the commit objects. We could remove it if it's a problem.

@HuiJun HuiJun requested a review from dlamoris January 25, 2021 19:12
commit.setComment(cmjs.getComment());

this.commitRepository.save(commit);
Optional<Commit> existing = this.commitRepository.findByCommitId(cmjs.getCommitId());
Copy link
Collaborator

Choose a reason for hiding this comment

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

cmjs.getId()

cmjs.setProjectId(projectId);

if (commitId != null && !commitId.isEmpty()) {
cmjs.setId(commitId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

there's somewhere else (initCommit)? that needs to be updated to check for existing id and generate docId


n.setDocId(e.getDocId());
n.setLastCommit(cmjs.getId());
n.setLastCommit(cmjs.getCommitId());
Copy link
Collaborator

Choose a reason for hiding this comment

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

getId()

case "deleted":
currentCommitCopy.getDeleted().add(action);
break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

can remove action here?

private List<CommitJson> getDocs(String commitId) {
try {
QueryBuilder commitQuery = QueryBuilders.boolQuery()
.should(QueryBuilders.termQuery(CommitJson.ID, commitId))
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is better as a filter instead of should

public class CommitElasticDAOImpl extends BaseElasticDAOImpl<CommitJson> implements CommitIndexDAO {

@Value("${elasticsearch.limit.index}")
int indexLimit;
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we be using the same limit for indexing vs splitting up commit? the commit can be a lot bigger than whatever we set the index limit to (currently used in bulk processor) (this is already injected in the BaseDao as bulkLimit)

partial.setId("");
}

if (partial.getAdded().isEmpty() && raw.getAdded() != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the first check should be here? this would only add addition data if partial is empty but we want to add them regardless

if (partial.getId() == null) {
partial.setId("");
}
if (partial.getId() == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

duplicate

if (partial.getComment().isEmpty() && raw.getComment() != null) {
partial.setComment(raw.getComment());
}
if (partial.getId().isEmpty() && raw.getCommitId() != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

duplicate

throw new BadRequestException(response.addMessage("Empty"));
}

@PostMapping(value = "/stream", consumes = MediaType.APPLICATION_JSON_VALUE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can comment this function out for now so it doesn't show up in generated swagger

}
return commits;
ArrayList<CommitJson> result = new ArrayList<>();
for (String key : rawCommits.keySet()) {
Copy link
Collaborator

@dlamoris dlamoris Jan 26, 2021

Choose a reason for hiding this comment

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

does using keySet retain ordering?
also because of the query, the commit objects returned wouldn't be the entire object if it was split - we used to just return the commit id and some metadata for element history, maybe we can just do that again

},
"response": []
},
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

revert deletion

"_projectId": {
"type": "keyword"
},
"_docId": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

revert

public static final String SOURCE = "source";

public static CommitJson copy(CommitJson original) {
CommitJson copy = new CommitJson();
Copy link
Collaborator

Choose a reason for hiding this comment

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

copy comment

@dlamoris dlamoris merged commit 060ef8c into develop Jan 28, 2021
@dlamoris dlamoris deleted the feature/commitRefactor branch January 28, 2021 19:54
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.

2 participants