From 89d2bcd59813b3dc9af08b3839fcda58d0e45d39 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Wed, 24 Nov 2021 22:16:11 -0600 Subject: [PATCH] Filter on additional fields (complete) --- src/subscription.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/subscription.rs b/src/subscription.rs index 9e188f3..e0916b6 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -122,8 +122,13 @@ impl ReqFilter { // determine if all populated fields in this filter match the provided event. // a filter matches an event if all the populated fields match. // Iterate through each filter field, return false if the field exists and doesn't match the event. + // order based on cost; id, time, kind, author, event if !self.id.as_ref().map(|v| v == &event.id).unwrap_or(true) { false + } else if !self.since.map(|t| event.created_at > t).unwrap_or(true) { + false + } else if !self.kind.map(|v| v == event.kind).unwrap_or(true) { + false } else if !self .author .as_ref() @@ -131,8 +136,6 @@ impl ReqFilter { .unwrap_or(true) { false - } else if !self.kind.map(|v| v == event.kind).unwrap_or(true) { - false } else if !self.author_match(&event.pubkey) { false } else if !self @@ -142,10 +145,6 @@ impl ReqFilter { .unwrap_or(true) { false - // event: Option, - // pubkey: Option, - // since: Option, - // authors: Option>, } else { true }