~williewillus/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH] Implement persistent trick storages

Details
Message ID
<20210513202739.455732-1-wenming.yi@gmail.com>
DKIM signature
pass
Download raw message
Patch: +5 -4
From: Alwinfy <20421383+Alwinfy@users.noreply.github.com>

---
nice
 main.rkt | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/main.rkt b/main.rkt
index 314de4e..dc1afba 100755
--- a/main.rkt
+++ b/main.rkt
@@ -283,7 +283,7 @@
  (let ([datum (and~> trick
                      trick-storage
                      (hash-ref (cdr (storage-info message type)) #f)
                      (with-input-from-bytes read)
                      (with-input-from-string read)
                      (with-handlers ([exn:fail:read? (const #f)]) _))])
    (and (not (eof-object? datum)) datum)))
(define/contract (write-storage trick message type data)
@@ -293,9 +293,9 @@
   (match-let ([(cons limit key) (storage-info message type)])
     (and
      key
      (let ([data (with-output-to-bytes (curry write data))])
      (let ([data (with-output-to-string (curry write data))])
        (and
         (<= (bytes-length data) limit)
         (<= (string-length data) limit)
         (begin
           (hash-set! (trick-storage trick) key data)
           #t)))))))
@@ -372,6 +372,7 @@
  (hasheq 'author (trick-author trick)
          'body (trick-body trick)
          'created (trick-created trick)
          'data (trick-storage trick)
          'invocations (trick-invocations trick)))

(define (json->trick json)
@@ -379,7 +380,7 @@
   (hash-ref json 'author)
   (hash-ref json 'body)
   (hash-ref json 'created)
   (make-hash) ; We purposefully don't save the trick storage due to space limits
   (hash-ref json 'data make-hash)
   (hash-ref json 'invocations)))

(define command-table
-- 
2.25.1
Reply to thread Export thread (mbox)