spring-projects / spring-projects/spring-data-couchbase

Support for Instant in doc.getExpiration() for Long-Term Expiry

Open
#2,006 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.