spring-projects / spring-projects/spring-data-couchbase
Support for Instant in doc.getExpiration() for Long-Term Expiry
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 284
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
I noticed that in the buildUpsertOptions and
buildInsertOptions methods, the doc.getExpiration() value is always converted to seconds using Duration.ofSeconds().
else if (doc.getExpiration() != 0) {
options.expiry(Duration.ofSeconds(doc.getExpiration()));
}
While options.expiry() can accept both Duration and Instant, converting the expiration exclusively to seconds can lead to limitations, especially for setting expirations greater than 50 years. This is because Couchbase supports durations up to 50 years when expressed as seconds, but longer durations must be provided as an Instant.
Suggestion
if (doc.getExpiration() > MAX_SECONDS_EXPIRATION) {
options.expiry(Instant.ofEpochSecond(doc.getExpiration()));
} else {
options.expiry(Duration.ofSeconds(doc.getExpiration()));
}
Does this approach align with the intended design of the buildUpsertOptions and buildInsertOptions methods, or are there other considerations that necessitate the current implementation?
Looking forward to your feedback and insights!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/main/java/org/springframework/data/couchbase/core/query/OptionsBuilder.java at buildUpsertOptions and buildInsertOptions, then review the Couchbase expiry API behavior for Duration and Instant. Done means expirations beyond the seconds limit use Instant while existing shorter expirations continue to use Duration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- database
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100