Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/halo-dev/halo into feat/add…
Browse files Browse the repository at this point in the history
…-node-card-placeholder
  • Loading branch information
LIlGG committed Jun 25, 2024
2 parents 1f3fafb + 4f63352 commit 357bf34
Show file tree
Hide file tree
Showing 148 changed files with 9,163 additions and 1,410 deletions.
1,709 changes: 1,677 additions & 32 deletions api-docs/openapi/v3_0/aggregated.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package run.halo.app.core.extension.content;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
import static run.halo.app.core.extension.content.Category.KIND;

Expand Down Expand Up @@ -53,12 +54,31 @@ public static class CategorySpec {

private String cover;

@Schema(requiredMode = NOT_REQUIRED, maxLength = 255)
private String template;

/**
* <p>Used to specify the template for the posts associated with the category.</p>
* <p>The priority is not as high as that of the post.</p>
* <p>If the post also specifies a template, the post's template will prevail.</p>
*/
@Schema(requiredMode = NOT_REQUIRED, maxLength = 255)
private String postTemplate;

@Schema(requiredMode = REQUIRED, defaultValue = "0")
private Integer priority;

private List<String> children;

/**
* <p>if a category is queried for related posts, the default behavior is to
* query all posts under the category including its subcategories, but if this field is
* set to true, cascade query behavior will be terminated here.</p>
* <p>For example, if a category has subcategories A and B, and A has subcategories C and
* D and C marked this field as true, when querying posts under A category,all posts under A
* and B will be queried, but C and D will not be queried.</p>
*/
private boolean preventParentPostCascadeQuery;
}

@JsonIgnore
Expand Down
11 changes: 10 additions & 1 deletion api/src/main/java/run/halo/app/extension/JsonExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
@JsonSerialize(using = JsonExtension.ObjectNodeExtensionSerializer.class)
@JsonDeserialize(using = JsonExtension.ObjectNodeExtensionDeSerializer.class)
class JsonExtension implements Extension {
public class JsonExtension implements Extension {

private final ObjectMapper objectMapper;

Expand Down Expand Up @@ -112,6 +112,15 @@ public ObjectNode getInternal() {
return objectNode;
}

/**
* Get object mapper.
*
* @return object mapper
*/
public ObjectMapper getObjectMapper() {
return objectMapper;
}

public MetadataOperator getMetadataOrCreate() {
var metadataNode = objectMapper.createObjectNode();
objectNode.set("metadata", metadataNode);
Expand Down
17 changes: 16 additions & 1 deletion api/src/main/java/run/halo/app/extension/ListOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,19 @@
public class ListOptions {
private LabelSelector labelSelector;
private FieldSelector fieldSelector;
}

@Override
public String toString() {
var sb = new StringBuilder();
if (fieldSelector != null) {
sb.append("fieldSelector: ").append(fieldSelector.query());
}
if (labelSelector != null) {
if (!sb.isEmpty()) {
sb.append(", ");
}
sb.append("labelSelector: ").append(labelSelector);
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ <E extends Extension> Mono<ListResult<E>> listBy(Class<E> type, ListOptions opti

<E extends Extension> Mono<E> get(Class<E> type, String name);

Mono<JsonExtension> getJsonExtension(GroupVersionKind gvk, String name);

/**
* Creates an Extension.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Sort;
import run.halo.app.extension.Extension;
import run.halo.app.extension.ExtensionClient;
import run.halo.app.extension.ExtensionMatcher;
Expand Down Expand Up @@ -58,7 +59,7 @@ public void start() {
listOptions.setFieldSelector(listMatcher.getFieldSelector());
listOptions.setLabelSelector(listMatcher.getLabelSelector());
}
indexedQueryEngine.retrieveAll(type, listOptions)
indexedQueryEngine.retrieveAll(type, listOptions, Sort.by("metadata.creationTimestamp"))
.forEach(name -> watcher.onAdd(new Request(name)));
}
client.watch(this.watcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import run.halo.app.extension.Extension;
import run.halo.app.extension.Unstructured;

@EqualsAndHashCode(callSuper = true)
public class FunctionalIndexAttribute<E extends Extension>
Expand Down Expand Up @@ -42,10 +41,6 @@ public Set<String> getValues(Extension object) {
*/
@Nullable
public String getValue(Extension object) {
if (object instanceof Unstructured unstructured) {
var ext = Unstructured.OBJECT_MAPPER.convertValue(unstructured, getObjectType());
return valueFunc.apply(ext);
}
if (getObjectType().isInstance(object)) {
return valueFunc.apply(getObjectType().cast(object));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.EqualsAndHashCode;
import org.springframework.util.Assert;
import run.halo.app.extension.Extension;
import run.halo.app.extension.Unstructured;

@EqualsAndHashCode(callSuper = true)
public class FunctionalMultiValueIndexAttribute<E extends Extension>
Expand All @@ -29,10 +28,6 @@ public FunctionalMultiValueIndexAttribute(Class<E> objectType,

@Override
public Set<String> getValues(Extension object) {
if (object instanceof Unstructured unstructured) {
var ext = Unstructured.OBJECT_MAPPER.convertValue(unstructured, getObjectType());
return getNonNullValues(ext);
}
if (getObjectType().isInstance(object)) {
return getNonNullValues(getObjectType().cast(object));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class IndexDescriptor {
private final IndexSpec spec;

/**
* Record whether the index is ready, managed by {@link IndexBuilder}.
* Record whether the index is ready, managed by {@code IndexBuilder}.
*/
private boolean ready;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.NavigableSet;
import run.halo.app.extension.Metadata;

/**
Expand Down Expand Up @@ -34,7 +34,7 @@
public interface IndexEntry {

/**
* Acquires the read lock for reading such as {@link #getByIndexKey(String)},
* Acquires the read lock for reading such as {@link #getObjectNamesBy(String)},
* {@link #entries()}, {@link #indexedKeys()}, because the returned result set of these
* methods is not immutable.
*/
Expand Down Expand Up @@ -87,7 +87,7 @@ public interface IndexEntry {
*
* @return distinct indexed keys of this entry.
*/
Set<String> indexedKeys();
NavigableSet<String> indexedKeys();

/**
* <p>Returns the entries of this entry in order.</p>
Expand All @@ -99,19 +99,34 @@ public interface IndexEntry {
Collection<Map.Entry<String, String>> entries();

/**
* Returns the immutable entries of this entry in order, it is safe to modify the returned
* result, but extra cost is made.
*
* @return immutable entries of this entry.
* <p>Returns the position of the object name in the indexed attribute value mapping for
* sorting.</p>
* For example:
* <pre>
* metadata.name | field1
* ------------- | ------
* foo | 1
* bar | 2
* baz | 2
* </pre>
* "field1" is the indexed attribute, and the position of the object name in the indexed
* attribute
* value mapping for sorting is:
* <pre>
* foo -> 0
* bar -> 1
* baz -> 1
* </pre>
* "bar" and "baz" have the same value, so they have the same position.
*/
Collection<Map.Entry<String, String>> immutableEntries();
Map<String, Integer> getIdPositionMap();

/**
* Returns the object names of this entry in order.
*
* @return object names of this entry.
*/
List<String> getByIndexKey(String indexKey);
List<String> getObjectNamesBy(String indexKey);

void clear();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package run.halo.app.extension.index;

import java.util.Collection;
import java.util.NavigableSet;
import java.util.Set;

public interface IndexEntryOperator {

/**
* Search all values that key less than the target key.
*
* @param key target key
* @param orEqual whether to include the value of the target key
* @return object names that key less than the target key
*/
NavigableSet<String> lessThan(String key, boolean orEqual);

/**
* Search all values that key greater than the target key.
*
* @param key target key
* @param orEqual whether to include the value of the target key
* @return object names that key greater than the target key
*/
NavigableSet<String> greaterThan(String key, boolean orEqual);

/**
* Search all values that key in the range of [start, end].
*
* @param start start key
* @param end end key
* @param startInclusive whether to include the value of the start key
* @param endInclusive whether to include the value of the end key
* @return object names that key in the range of [start, end]
*/
NavigableSet<String> range(String start, String end, boolean startInclusive,
boolean endInclusive);

/**
* Find all values that key equals to the target key.
*
* @param key target key
* @return object names that key equals to the target key
*/
NavigableSet<String> find(String key);

NavigableSet<String> findIn(Collection<String> keys);

/**
* Get all values in the index entry.
*
* @return a set of all object names
*/
Set<String> getValues();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package run.halo.app.extension.index;

import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.NavigableSet;
import java.util.Set;
import java.util.TreeSet;
import org.springframework.util.Assert;

public class IndexEntryOperatorImpl implements IndexEntryOperator {
private final IndexEntry indexEntry;

public IndexEntryOperatorImpl(IndexEntry indexEntry) {
this.indexEntry = indexEntry;
}

private static NavigableSet<String> createNavigableSet() {
return new TreeSet<>(KeyComparator.INSTANCE);
}

@Override
public NavigableSet<String> lessThan(String key, boolean orEqual) {
Assert.notNull(key, "Key must not be null.");
indexEntry.acquireReadLock();
try {
var navigableIndexedKeys = indexEntry.indexedKeys();
var headSetKeys = navigableIndexedKeys.headSet(key, orEqual);
return findIn(headSetKeys);
} finally {
indexEntry.releaseReadLock();
}
}

@Override
public NavigableSet<String> greaterThan(String key, boolean orEqual) {
Assert.notNull(key, "Key must not be null.");
indexEntry.acquireReadLock();
try {
var navigableIndexedKeys = indexEntry.indexedKeys();
var tailSetKeys = navigableIndexedKeys.tailSet(key, orEqual);
return findIn(tailSetKeys);
} finally {
indexEntry.releaseReadLock();
}
}

@Override
public NavigableSet<String> range(String start, String end, boolean startInclusive,
boolean endInclusive) {
Assert.notNull(start, "The start must not be null.");
Assert.notNull(end, "The end must not be null.");
indexEntry.acquireReadLock();
try {
var navigableIndexedKeys = indexEntry.indexedKeys();
var tailSetKeys = navigableIndexedKeys.subSet(start, startInclusive, end, endInclusive);
return findIn(tailSetKeys);
} finally {
indexEntry.releaseReadLock();
}
}

@Override
public NavigableSet<String> find(String key) {
Assert.notNull(key, "The key must not be null.");
indexEntry.acquireReadLock();
try {
var resultSet = createNavigableSet();
var result = indexEntry.getObjectNamesBy(key);
if (result != null) {
resultSet.addAll(result);
}
return resultSet;
} finally {
indexEntry.releaseReadLock();
}
}

@Override
public NavigableSet<String> findIn(Collection<String> keys) {
if (keys == null || keys.isEmpty()) {
return createNavigableSet();
}
indexEntry.acquireReadLock();
try {
var keysToSearch = new HashSet<>(keys);
var resultSet = createNavigableSet();
for (var entry : indexEntry.entries()) {
if (keysToSearch.contains(entry.getKey())) {
resultSet.add(entry.getValue());
}
}
return resultSet;
} finally {
indexEntry.releaseReadLock();
}
}

@Override
public Set<String> getValues() {
indexEntry.acquireReadLock();
try {
Set<String> uniqueValues = new HashSet<>();
for (Map.Entry<String, String> entry : indexEntry.entries()) {
uniqueValues.add(entry.getValue());
}
return uniqueValues;
} finally {
indexEntry.releaseReadLock();
}
}
}
Loading

0 comments on commit 357bf34

Please sign in to comment.