row = db.query(
                 """
                 UPDATE users_push_subscriptions
-                SET userid = ?, subscription = ?
+                SET subscription = ?
                 WHERE subid = ? AND userid = ?
                 RETURNING subid
                 """,
-                [g.userid, json.dumps(request.json), subid, g.userid], expect_one=True)
+                [json.dumps(request.json), subid, g.userid], expect_one=True)
+        current_app.logger.info(f"{g.username} updated push subscription {row['subid']}")
     else:
         row = db.query(
                 """
                 RETURNING subid
                 """,
                 [g.userid, json.dumps(request.json), 0], expect_one=True)
+        current_app.logger.info(f"{g.username} registered push subscription {row['subid']}")
     db.commit()
 
-    current_app.logger.info(f"{g.username} registered push subscription")
-
     return {"status": "success", "subid": row["subid"]}
 
 @bp.post("/update-subscription/<int:subid>")
 
 }
 
 async function periodicPushSync() {
-    console.log("sync");
     if (!("serviceWorker" in navigator)) {
         return;  // No service woker available
     }
     const subid = window.localStorage.getItem("subid");
-    console.log(subid);
     if (subid) {
         await syncPushSubscription();
     }
 }
 
 async function syncPushSubscription() {
+    if (Notification.permission != "granted") {
+        return;
+    }
     const registration = await navigator.serviceWorker.getRegistration();
     let subscription = await registration.pushManager.getSubscription();
     if (!subscription)
     );
 
     const rspJson = await response.json();
-    console.log("Subscription ID:", rspJson.subid);
     window.localStorage.setItem("subid", rspJson.subid);
 }
 
 periodicPushSync();
-setInterval(periodicPushSync, 10000);
+setInterval(periodicPushSync, 60*60*1000);
 
 
     // Prevent this from getting called again on the next page load
     document.removeEventListener("DOMContentLoaded", updateSelections);
 
-    if (window.localStorage.getItem("subid"))
+    if (localStorage.getItem("subid") && Notification.permission == "granted")
     {
         const params = new URLSearchParams({subid: window.localStorage.getItem("subid")});
         fetch(`/push-notifications/settings?${params}`).then((r) => {
             });
         })
     }
+    else {
+        document.getElementById("comment-push").checked = false;
+        document.getElementById("song-push").checked = false;
+    }
 }
 document.addEventListener("DOMContentLoaded", updateSelections());