You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2025/03/14 10:38:11 UTC
(james-project) 01/01: [ENHANCEMENT] Allow setting a preview for TTL
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch preview-ttl
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit d0aa4da771284cbdf6863b237e417a96eaddfa21
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Mar 14 11:37:42 2025 +0100
[ENHANCEMENT] Allow setting a preview for TTL
---
docs/modules/servers/partials/configure/jmap.adoc | 8 ++++++++
.../sample-configuration/jvm.properties | 4 ++++
.../CassandraMessageFastViewProjection.java | 24 +++++++++++++++++-----
3 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/docs/modules/servers/partials/configure/jmap.adoc b/docs/modules/servers/partials/configure/jmap.adoc
index b2f0419844..2691fabbd3 100644
--- a/docs/modules/servers/partials/configure/jmap.adoc
+++ b/docs/modules/servers/partials/configure/jmap.adoc
@@ -109,6 +109,14 @@ This allows to prevent users from using some specific JMAP extensions.
|===
+In cassandra we can set an expiry for preview in an attempt to mitigate disk space usage. In `jvm.properties`:
+
+....
+# Previews takes roughly 10% DB space though can easily be recomputed. Storing preview for historical preview is
+# also needless. This property allows setting an expiry for previews.
+# james.jmap.preview.ttl=30d
+....
+
== Wire tapping
Enabling *TRACE* on `org.apache.james.jmap.wire` enables reactor-netty wiretap, logging of
diff --git a/server/apps/distributed-app/sample-configuration/jvm.properties b/server/apps/distributed-app/sample-configuration/jvm.properties
index 20b9d1c067..8509aeb856 100644
--- a/server/apps/distributed-app/sample-configuration/jvm.properties
+++ b/server/apps/distributed-app/sample-configuration/jvm.properties
@@ -106,3 +106,7 @@ jmx.remote.x.mlet.allow.getMBeansFromURL=false
# Allow users to have rights for shares of different domain. Defaults to false.
#james.rights.crossdomain.allow=false
+
+# Previews takes roughly 10% DB space though can easily be recomputed. Storing preview for historical preview is
+# also needless. This property allows setting an expiry for previews.
+# james.jmap.preview.ttl=30d
diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java
index e2a22ff790..330020cd23 100644
--- a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java
+++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java
@@ -28,6 +28,9 @@ import static org.apache.james.jmap.cassandra.projections.table.CassandraMessage
import static org.apache.james.jmap.cassandra.projections.table.CassandraMessageFastViewProjectionTable.PREVIEW;
import static org.apache.james.jmap.cassandra.projections.table.CassandraMessageFastViewProjectionTable.TABLE_NAME;
+import java.time.Duration;
+import java.util.Optional;
+
import jakarta.inject.Inject;
import org.apache.james.backends.cassandra.init.configuration.JamesExecutionProfiles;
@@ -39,6 +42,7 @@ import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
import org.apache.james.mailbox.model.MessageId;
import org.apache.james.metrics.api.Metric;
import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.util.DurationParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,6 +59,10 @@ import reactor.core.publisher.Mono;
public class CassandraMessageFastViewProjection implements MessageFastViewProjection {
public static final Logger LOGGER = LoggerFactory.getLogger(CassandraMessageFastViewProjection.class);
+
+ private static final Optional<Duration> TTL = Optional.ofNullable(System.getProperty("james.jmap.preview.ttl", null))
+ .map(DurationParser::parse);
+
private final Metric metricRetrieveHitCount;
private final Metric metricRetrieveMissCount;
@@ -74,11 +82,17 @@ public class CassandraMessageFastViewProjection implements MessageFastViewProjec
.whereColumn(MESSAGE_ID).isEqualTo(bindMarker(MESSAGE_ID))
.build());
- this.storeStatement = session.prepare(insertInto(TABLE_NAME)
- .value(MESSAGE_ID, bindMarker(MESSAGE_ID))
- .value(PREVIEW, bindMarker(PREVIEW))
- .value(HAS_ATTACHMENT, bindMarker(HAS_ATTACHMENT))
- .build());
+ this.storeStatement = TTL.map(ttl -> session.prepare(insertInto(TABLE_NAME)
+ .value(MESSAGE_ID, bindMarker(MESSAGE_ID))
+ .value(PREVIEW, bindMarker(PREVIEW))
+ .value(HAS_ATTACHMENT, bindMarker(HAS_ATTACHMENT))
+ .usingTtl((int) ttl.getSeconds())
+ .build()))
+ .orElseGet(() -> session.prepare(insertInto(TABLE_NAME)
+ .value(MESSAGE_ID, bindMarker(MESSAGE_ID))
+ .value(PREVIEW, bindMarker(PREVIEW))
+ .value(HAS_ATTACHMENT, bindMarker(HAS_ATTACHMENT))
+ .build()));
this.retrieveStatement = session.prepare(selectFrom(TABLE_NAME)
.all()
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org