Re: [PATCH damus v2 2/2] Mute reposts of muted events

5 views
Skip to first unread message

Daniel D'Aquino

unread,
May 24, 2024, 9:22:52 PM5/24/24
to William Casarin, sembene_truestar via patches, dev


On May 24, 2024, at 18:09, Daniel D'Aquino <dan...@daquino.me> wrote:



On May 24, 2024, at 16:54, William Casarin <jb...@jb55.com> wrote:

On Fri, May 24, 2024 at 10:58:59PM GMT, Daniel D’Aquino wrote:
Testing
--------

PASS

Device: iPhone 15 simulator
iOS: 17.4
Damus: This commit
Steps:
1. Mute a specific user "A" from account "B"
2. Make account "B" follow account "C"
3. Using a separate account "C", repost a note from account "A"
4. Make sure that the reposted note from step 3 does not appear on account "B"'s timeline
5. Make sure other reposts of other users still show normally

Closes: https://github.com/damus-io/damus/issues/1934
Changelog-Changed: Do not show reposts of muted events
Signed-off-by: Daniel D’Aquino <dan...@daquino.me>
---
damus/Models/MutelistManager.swift |  5 +++++
nostrdb/NdbNote.swift              | 13 +++++++++++++
2 files changed, 18 insertions(+)

[..]

diff --git a/nostrdb/NdbNote.swift b/nostrdb/NdbNote.swift
index ce2f358f..445196e2 100644
--- a/nostrdb/NdbNote.swift
+++ b/nostrdb/NdbNote.swift
@@ -272,6 +272,19 @@ class NdbNote: Encodable, Equatable, Hashable {
   func get_inner_event() -> NdbNote? {
       return self.inner_event
   }
+
+    func get_inner_event(ndb: Ndb) -> NdbNote? {
+        guard self.known_kind == .boost else {
+            return nil
+        }
+
+        if let id = self.referenced_ids.first {
+            guard let note_key = ndb.lookup_note_key(id) else { return nil }
+            return ndb.lookup_note_by_key(note_key)?.unsafeUnownedValue?.to_owned()
+        }

my only concern here is that this is pretty inefficient, ideally if we
are copying notes into memory it would not be a one-off things.

Since this is a temporary, instead of doing to_owned we can just return
NdbTxn<NdbNote>. This way we won't need a copy and you can refer to the
n ote data within nostrdb:

  func get_inner_event(ndb: Ndb) -> NdbTxn<NdbNote>? {
      guard self.known_kind == .boost else {
          return nil
      }

      if let id = self.referenced_ids.first {
          guard let note_key = ndb.lookup_note_key(id) else { return nil }
          return ndb.lookup_note_by_key(note_key).collect()
      }

      return  nil
  }

  // ...

  if let inner_event = ev.get_inner_event(ndb: self.ndb) {
      return self.compute_event_muted_reason(inner_event.unsafeUnownedValue)
  }

I see! v3 coming up soon!


NostrDB question. NostrDB transactions keep memory pages open and prevent them from being overwritten unexpectedly by concurrently executing code. However, if we pass around that NdbTxn<NdbNote> object, does it guarantee the transaction will remain open and thus our NdbNote will be there?

In other words, if we write some code in Swift that keeps the reference count to the NdbTxn object above zero (preventing NdbTxn from being garbage collected by Swift), is it safe to access the underlying NdbNote?

William Casarin

unread,
May 27, 2024, 7:44:45 PM5/27/24
to Daniel D'Aquino, pat...@damus.io, dev
On Sat, May 25, 2024 at 01:22:45AM GMT, Daniel D'Aquino wrote:
>
>NostrDB question. NostrDB transactions keep memory pages open and
>prevent them from being overwritten unexpectedly by concurrently
>executing code. However, if we pass around that NdbTxn<NdbNote> object,
>does it guarantee the transaction will remain open and thus our NdbNote
>will be there?
>
>In other words, if we write some code in Swift that keeps the reference
>count to the NdbTxn object above zero (preventing NdbTxn from being
>garbage collected by Swift), is it safe to access the underlying
>NdbNote?

yeah NdbTxn opens a transaction in its constructor and closes that
transaction in its destructor. So as long as its in scope the data it
refers to will be valid.

These should never be stored though, as long running transactions will
keep holding onto pages forever which is bad.
Reply all
Reply to author
Forward
0 new messages