Sort combined events in repository.query
This commit is contained in:
@@ -74,7 +74,7 @@
|
||||
padding: 0.5rem 1rem;
|
||||
text-align: left;
|
||||
transition-duration: 100ms;
|
||||
transition-property: color background-color;
|
||||
transition-property: color, background-color;
|
||||
background-color: var(--tiptap-object-bg);
|
||||
color: var(--tiptap-object-fg);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ export class Repository<E extends HashedEvent = TrustedEvent> extends Emitter {
|
||||
const applied = this._applyAnyFilter(originalFilter)
|
||||
const filter = applied?.filter || originalFilter
|
||||
const events = applied ? this._getEvents(applied!.ids) : this.dump()
|
||||
const sorted = shouldSort ? sortBy((e: E) => -e.created_at, events) : events
|
||||
const sorted = this._sortEvents(shouldSort && Boolean(filter.limit), events)
|
||||
|
||||
const chunk: E[] = []
|
||||
for (const event of sorted) {
|
||||
@@ -145,7 +145,10 @@ export class Repository<E extends HashedEvent = TrustedEvent> extends Emitter {
|
||||
result.push(chunk)
|
||||
}
|
||||
|
||||
return uniq(flatten(result))
|
||||
// Only re-sort if we had multiple filters, or if our single filter wasn't sorted
|
||||
const shouldSortAll = shouldSort && (filters.length > 1 || !filters[0]?.limit)
|
||||
|
||||
return this._sortEvents(shouldSortAll, uniq(flatten(result)))
|
||||
}
|
||||
|
||||
publish = (event: E, {shouldNotify = true} = {}): boolean => {
|
||||
@@ -229,6 +232,9 @@ export class Repository<E extends HashedEvent = TrustedEvent> extends Emitter {
|
||||
|
||||
// Utilities
|
||||
|
||||
_sortEvents = (shouldSort: boolean, events: E[]) =>
|
||||
shouldSort ? sortBy(e => -e.created_at, events) : events
|
||||
|
||||
_updateIndex = <K>(m: Map<K, E[]>, k: K, add?: E, remove?: E) => {
|
||||
let a = m.get(k) || []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user