Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding comments + refactor
  • Loading branch information
gabe-lyons committed Jun 22, 2021
commit 43477eecbd76474a78a6e3524b88dad4ff77065a
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,20 @@ public Map<Urn, List<RecordTemplate>> getLatestAspects(@Nonnull final Set<Urn> u
return urnToAspects;
}

/*
* When a user tries to fetch a negative version, we want to index most recent to least recent snapshots.
* To do this, we want to fetch the maximum version and subtract the negative version from that. Since -1 represents
* the maximum version, we need to add 1 to the final result.
*/
private long calculateVersionNumber(@Nonnull final Urn urn, @Nonnull final String aspectName, @Nonnull long version) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a preconditions.assert that version is indeed negative when passed into this method?

return _entityDao.getMaxVersion(urn.toString(), aspectName) + version + 1;
}

@Override
@Nullable
public RecordTemplate getAspect(@Nonnull final Urn urn, @Nonnull final String aspectName, @Nonnull long version) {
if (version < 0) {
version = _entityDao.getMaxVersion(urn.toString(), aspectName) + version + 1;
version = calculateVersionNumber(urn, aspectName, version);
}
final EbeanAspectV2.PrimaryKey primaryKey = new EbeanAspectV2.PrimaryKey(urn.toString(), aspectName, version);
final Optional<EbeanAspectV2> maybeAspect = Optional.ofNullable(_entityDao.getAspect(primaryKey));
Expand All @@ -109,7 +118,7 @@ public VersionedAspect getVersionedAspect(@Nonnull Urn urn, @Nonnull String aspe
VersionedAspect result = new VersionedAspect();

if (version < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we move this check inside the method? so callers don't have to check if version is positive or negative?

version = _entityDao.getMaxVersion(urn.toString(), aspectName) + version + 1;
version = calculateVersionNumber(urn, aspectName, version);
}

final EbeanAspectV2.PrimaryKey primaryKey = new EbeanAspectV2.PrimaryKey(urn.toString(), aspectName, version);
Expand Down