1
0
Эх сурвалжийг харах

enhance: DO ws hibernation

Tienson Qin 1 сар өмнө
parent
commit
9e592aa373

+ 0 - 1
deps/db-sync/src/logseq/db_sync/storage.cljs

@@ -119,7 +119,6 @@
         created-at (common/now-ms)
         created-at (common/now-ms)
         normalized-data (->> tx-data
         normalized-data (->> tx-data
                              (db-normalize/normalize-tx-data db-after db-before))
                              (db-normalize/normalize-tx-data db-after db-before))
-        _ (prn :debug :normalized-data normalized-data)
         tx-str (common/write-transit normalized-data)]
         tx-str (common/write-transit normalized-data)]
     (append-tx! sql new-t tx-str created-at)))
     (append-tx! sql new-t tx-str created-at)))
 
 

+ 12 - 2
deps/db-sync/src/logseq/db_sync/worker.cljs

@@ -162,7 +162,8 @@
 
 
 (defn- add-presence!
 (defn- add-presence!
   [^js self ^js ws user]
   [^js self ^js ws user]
-  (swap! (presence* self) assoc ws user))
+  (swap! (presence* self) assoc ws user)
+  (.serializeAttachment ws (clj->js user)))
 
 
 (defn- update-presence!
 (defn- update-presence!
   [^js self ^js ws {:keys [editing-block-uuid] :as updates}]
   [^js self ^js ws {:keys [editing-block-uuid] :as updates}]
@@ -175,6 +176,7 @@
                              (assoc user :editing-block-uuid editing-block-uuid)
                              (assoc user :editing-block-uuid editing-block-uuid)
                              (dissoc user :editing-block-uuid))
                              (dissoc user :editing-block-uuid))
                            user)]
                            user)]
+               (.serializeAttachment ws (clj->js user'))
                (assoc presence ws user'))
                (assoc presence ws user'))
              presence))))
              presence))))
 
 
@@ -840,7 +842,15 @@
                (set! (.-env this) env)
                (set! (.-env this) env)
                (set! (.-sql this) (.-sql ^js (.-storage state)))
                (set! (.-sql this) (.-sql ^js (.-storage state)))
                (set! (.-conn this) nil)
                (set! (.-conn this) nil)
-               (set! (.-schema-ready this) false))
+               (set! (.-schema-ready this) false)
+               (let [presence (presence* this)
+                     sockets (.getWebSockets state)]
+                 (doseq [^js ws sockets]
+                   (when-let [attachment (.deserializeAttachment ws)]
+                     (swap! presence assoc ws (js->clj attachment :keywordize-keys true))))
+                 (.setWebSocketAutoResponse
+                  state
+                  (js/WebSocketRequestResponsePair. "ping" "pong"))))
 
 
   Object
   Object
   (fetch [this request]
   (fetch [this request]

+ 2 - 1
deps/db-sync/worker/wrangler.toml

@@ -35,6 +35,7 @@ name = "logseq-sync"
 COGNITO_JWKS_URL = "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_dtagLnju8/.well-known/jwks.json"
 COGNITO_JWKS_URL = "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_dtagLnju8/.well-known/jwks.json"
 COGNITO_ISSUER = "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_dtagLnju8"
 COGNITO_ISSUER = "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_dtagLnju8"
 COGNITO_CLIENT_ID = "69cs1lgme7p8kbgld8n5kseii6"
 COGNITO_CLIENT_ID = "69cs1lgme7p8kbgld8n5kseii6"
+ENABLE_DB_SYNC_LOCAL = "true"
 
 
 [[env.staging.durable_objects.bindings]]
 [[env.staging.durable_objects.bindings]]
 name = "LOGSEQ_SYNC_DO"
 name = "LOGSEQ_SYNC_DO"
@@ -51,4 +52,4 @@ bucket_name = "logseq-sync-assets-dev"
 [[env.staging.d1_databases]]
 [[env.staging.d1_databases]]
 binding = "DB"
 binding = "DB"
 database_name = "logseq-sync-graph-meta-staging"
 database_name = "logseq-sync-graph-meta-staging"
-database_id = "REPLACE_WITH_D1_DATABASE_ID"
+database_id = "00325aa2-c805-4693-b599-900a25dcde42"