Skip to content

Commit

Permalink
core: Fixed index modified time to be unset for cache storage
Browse files Browse the repository at this point in the history
This is necessary to retrieve the proper modified time from the
source storage, instead of using the current date and time.
  • Loading branch information
cederberg committed Dec 31, 2023
1 parent bf4ca8e commit c827a6f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/java/org/rapidcontext/app/model/ApiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public static Object serialize(Path path,
boolean hidden = opts.get("hidden", Boolean.class, false);
return new Dict()
.set("type", "index")
.set("modified", idx.modified())
.set("modified", Objects.requireNonNullElse(idx.modified(), new Date()))
.set("paths", Array.from(idx.paths(path, hidden)));
} else if (obj instanceof Binary) {
Binary data = (Binary) obj;
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/rapidcontext/app/plugin/PluginZipStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.rapidcontext.core.storage.Index;
Expand Down Expand Up @@ -53,7 +54,7 @@ public PluginZipStorage(String pluginId, File zipFile) throws IOException {
root.removeObject(legacyPath.name());
paths.remove(legacyPath);
entries.remove(legacyPath);
Index idx = new Index();
Index idx = new Index(new Date());
root.addIndex(Plugin.PATH.name());
paths.put(Plugin.PATH, Plugin.PATH);
entries.put(Plugin.PATH, idx);
Expand Down
11 changes: 2 additions & 9 deletions src/java/org/rapidcontext/core/storage/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,10 @@ public static Index merge(Index one, Index two) {
}
}

/**
* Creates a new empty index modified right now.
*/
public Index() {
this(new Date());
}

/**
* Creates a new empty index.
*
* @param modified the last modified date
* @param modified the last modified date, or null for unknown
*/
public Index(Date modified) {
this.modified = modified;
Expand Down Expand Up @@ -121,7 +114,7 @@ public boolean isEmpty() {
/**
* Returns the last modified date.
*
* @return the last modified date
* @return the last modified date, or null if unknown
*/
public Date modified() {
return this.modified;
Expand Down
4 changes: 1 addition & 3 deletions src/java/org/rapidcontext/core/storage/MemoryStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,12 @@ private void remove(Path path, boolean updateParent) {
*/
private void indexInsert(Path path) {
Path parent = path.parent();
Index idx = Objects.requireNonNullElse((Index) objects.get(parent), new Index());
Index idx = Objects.requireNonNullElse((Index) objects.get(parent), new Index(null));
if (path.isIndex()) {
idx.addIndex(path.name());
} else {
idx.addObject(path.name());
}
idx.setModified(null);
if (!objects.containsKey(parent)) {
objects.put(parent, idx);
meta.put(parent, new Metadata(Index.class, parent, Path.ROOT, null));
Expand All @@ -267,7 +266,6 @@ private void indexRemove(Path path) {
} else {
idx.removeObject(path.name());
}
idx.setModified(null);
if (idx.isEmpty()) {
objects.remove(parent);
meta.remove(parent);
Expand Down

0 comments on commit c827a6f

Please sign in to comment.