Make sorting/limit more resilient in repository
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman",
|
"name": "@welshman",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/app",
|
"name": "@welshman/app",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of svelte stores for use in building nostr client applications.",
|
"description": "A collection of svelte stores for use in building nostr client applications.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/content",
|
"name": "@welshman/content",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of utilities for parsing nostr note content.",
|
"description": "A collection of utilities for parsing nostr note content.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/editor",
|
"name": "@welshman/editor",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A batteries-included nostr editor.",
|
"description": "A batteries-included nostr editor.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/feeds",
|
"name": "@welshman/feeds",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "Utilities for building dynamic nostr feeds.",
|
"description": "Utilities for building dynamic nostr feeds.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/lib",
|
"name": "@welshman/lib",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of utilities.",
|
"description": "A collection of utilities.",
|
||||||
|
|||||||
@@ -1517,9 +1517,9 @@ export const prop =
|
|||||||
|
|
||||||
/** Returns a function that adds/updates a property on object */
|
/** Returns a function that adds/updates a property on object */
|
||||||
export const assoc =
|
export const assoc =
|
||||||
<K extends string, T, U>(k: K, v: T) =>
|
<K extends string, T>(k: K, v: T) =>
|
||||||
(o: U) =>
|
<U>(o: U): U =>
|
||||||
({...o, [k as K]: v}) as U & Record<K, T>
|
({...o, [k]: v}) as U
|
||||||
|
|
||||||
/** Returns a function that removes a property on object */
|
/** Returns a function that removes a property on object */
|
||||||
export const dissoc =
|
export const dissoc =
|
||||||
|
|||||||
@@ -154,10 +154,6 @@ describe("Repository", () => {
|
|||||||
repo = new Repository()
|
repo = new Repository()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should throw on invalid queries", () => {
|
|
||||||
expect(() => repo.query([{limit: 10}], {shouldSort: false})).toThrow()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should query by ids", () => {
|
it("should query by ids", () => {
|
||||||
const event = createEvent(1)
|
const event = createEvent(1)
|
||||||
repo.publish(event)
|
repo.publish(event)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/net",
|
"name": "@welshman/net",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "Utilities for connecting with nostr relays.",
|
"description": "Utilities for connecting with nostr relays.",
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ export const pull = async ({context, ...options}: PullOptions) => {
|
|||||||
await Promise.all(
|
await Promise.all(
|
||||||
Array.from(idsByRelay.entries()).map(([relay, allIds]) => {
|
Array.from(idsByRelay.entries()).map(([relay, allIds]) => {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
chunk(500, allIds).map(
|
chunk(100, allIds).map(
|
||||||
ids =>
|
ids =>
|
||||||
new Promise<void>(resolve =>
|
new Promise<void>(resolve =>
|
||||||
requestOne({
|
requestOne({
|
||||||
|
|||||||
@@ -154,15 +154,11 @@ export class Repository extends Emitter {
|
|||||||
) => {
|
) => {
|
||||||
const result: TrustedEvent[][] = []
|
const result: TrustedEvent[][] = []
|
||||||
for (const originalFilter of filters) {
|
for (const originalFilter of filters) {
|
||||||
if (originalFilter.limit !== undefined && !shouldSort) {
|
|
||||||
throw new Error("Unable to skip sorting if limit is defined")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to fulfill the query using one of our indexes. Fall back to all events.
|
// Attempt to fulfill the query using one of our indexes. Fall back to all events.
|
||||||
const applied = this._applyAnyFilter(originalFilter)
|
const applied = this._applyAnyFilter(originalFilter)
|
||||||
const filter = applied?.filter || originalFilter
|
const filter = applied?.filter || originalFilter
|
||||||
const events = applied ? this._getEvents(applied!.ids) : this.dump()
|
const events = applied ? this._getEvents(applied!.ids) : this.dump()
|
||||||
const sorted = this._sortEvents(shouldSort && Boolean(filter.limit), events)
|
const sorted = this._sortEvents(shouldSort || Boolean(filter.limit), events)
|
||||||
|
|
||||||
const chunk: TrustedEvent[] = []
|
const chunk: TrustedEvent[] = []
|
||||||
for (const event of sorted) {
|
for (const event of sorted) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/router",
|
"name": "@welshman/router",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of utilities for nostr relay selection.",
|
"description": "A collection of utilities for nostr relay selection.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/signer",
|
"name": "@welshman/signer",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A nostr signer implemenation supporting several login methods.",
|
"description": "A nostr signer implemenation supporting several login methods.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/store",
|
"name": "@welshman/store",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of utilities based on svelte/store for use with welshman",
|
"description": "A collection of utilities based on svelte/store for use with welshman",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/util",
|
"name": "@welshman/util",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of nostr-related utilities.",
|
"description": "A collection of nostr-related utilities.",
|
||||||
|
|||||||
Reference in New Issue
Block a user