-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/halo-dev/halo into feat/add…
…-node-card-placeholder
- Loading branch information
Showing
148 changed files
with
9,163 additions
and
1,410 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
api/src/main/java/run/halo/app/extension/index/IndexEntryOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
112 changes: 112 additions & 0 deletions
112
api/src/main/java/run/halo/app/extension/index/IndexEntryOperatorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.