Skip to content

Commit

Permalink
move drop-refresh-spam to flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dwwoelfel committed Nov 26, 2024
1 parent 474819d commit bed51da
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 113 deletions.
140 changes: 76 additions & 64 deletions server/flags-config/instant.perms.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,91 @@
export default {
"attrs": {
"allow": {
"create": "false"
}
// Docs: https://www.instantdb.com/docs/permissions

const rules = {
attrs: {
allow: {
create: "false",
},
},
"storage-whitelist": {
"allow": {
"view": "false",
"create": "false",
"delete": "false",
"update": "false"
}
allow: {
view: "false",
create: "false",
delete: "false",
update: "false",
},
},
"friend-emails": {
"allow": {
"view": "false",
"create": "false",
"delete": "false",
"update": "false"
}
allow: {
view: "false",
create: "false",
delete: "false",
update: "false",
},
},
"view-checks": {
"allow": {
"view": "false",
"create": "false",
"delete": "false",
"update": "false"
}
},
"app-users-to-triples-migration": {
"allow": {
"view": "false",
"create": "false",
"delete": "false",
"update": "false"
}
allow: {
view: "false",
create: "false",
delete: "false",
update: "false",
},
},
"power-user-emails": {
"allow": {
"view": "false",
"create": "false",
"delete": "false",
"update": "false"
}
allow: {
view: "false",
create: "false",
delete: "false",
update: "false",
},
},
"test-emails": {
"allow": {
"view": "false",
"create": "false",
"delete": "false",
"update": "false"
}
allow: {
view: "false",
create: "false",
delete: "false",
update: "false",
},
},
"promo-emails": {
"allow": {
"view": "false",
"create": "false",
"delete": "false",
"update": "false"
}
allow: {
view: "false",
create: "false",
delete: "false",
update: "false",
},
},
hazelcast: {
allow: {
view: "false",
create: "false",
delete: "false",
update: "false",
},
},
"hazelcast": {
"allow": {
"view": "false",
"create": "false",
"delete": "false",
"update": "false"
}
"drop-refresh-spam": {
allow: {
view: "false",
create: "false",
delete: "false",
update: "false",
},
},
custodian: {
allow: {
view: "false",
create: "false",
delete: "false",
update: "false",
},
},
"team-emails": {
"allow": {
"view": "false",
"create": "false",
"delete": "false",
"update": "false"
}
}
};
allow: {
view: "false",
create: "false",
delete: "false",
update: "false",
},
},
};

export default rules;
46 changes: 23 additions & 23 deletions server/flags-config/instant.schema.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
// instant-config
// https://instantdb.com/dash?s=main&t=home&app=24a4d71b-7bb2-4630-9aee-01146af26239
// http://localhost:3000/dash?s=main&t=home&app=24a4d71b-7bb2-4630-9aee-01146af26239
// Docs: https://www.instantdb.com/docs/schema

import { i } from "@instantdb/core";

const graph = i.graph(
{
"$users": i.entity({
"email": i.string().unique().indexed(),
$users: i.entity({
email: i.string().unique().indexed(),
}),
"app-users-to-triples-migration": i.entity({
"appId": i.string(),
"processId": i.string(),
"drop-refresh-spam": i.entity({
"default-value": i.boolean(),
"disabled-apps": i.any(),
"enabled-apps": i.any(),
}),
"friend-emails": i.entity({
"email": i.string().unique(),
email: i.string().unique(),
}),
"hazelcast": i.entity({
hazelcast: i.entity({
"default-value": i.boolean(),
"disabled": i.boolean(),
disabled: i.boolean(),
"disabled-apps": i.any(),
"enabled-apps": i.any(),
}),
"power-user-emails": i.entity({
"email": i.string().unique(),
email: i.string().unique(),
}),
"promo-emails": i.entity({
"email": i.string(),
email: i.string(),
}),
"storage-whitelist": i.entity({
"appId": i.string().unique().indexed(),
"email": i.string(),
"isEnabled": i.boolean(),
appId: i.string().unique().indexed(),
email: i.string(),
isEnabled: i.boolean(),
}),
"team-emails": i.entity({
"email": i.string(),
email: i.string(),
}),
"test-emails": i.entity({
"email": i.string(),
}),
"view-checks": i.entity({
"default-value": i.boolean(),
"disabled-apps": i.any(),
"enabled-apps": i.any(),
email: i.string(),
}),
},
{}
// You can define links here.
// For example, if `posts` should have many `comments`.
// More in the docs:
// https://www.instantdb.com/docs/schema#defining-links
{},
);

export default graph;
2 changes: 0 additions & 2 deletions server/src/instant/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
(when-let [app-id (System/getenv "INSTANT_ON_INSTANT_APP_ID")]
(parse-uuid app-id)))

(def drop-refresh-spam? (= "true" (System/getenv "DROP_REFRESH_SPAM")))

(defn db-url->config [url]
(cond (string/starts-with? url "jdbc")
{:jdbcUrl url}
Expand Down
34 changes: 31 additions & 3 deletions server/src/instant/flags.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
:storage-whitelist {}
:team-emails {}
:test-emails {}
:view-checks {}
:hazelcast {}
:drop-refresh-spam {}
:promo-emails {}})

(defn transform-query-result
Expand Down Expand Up @@ -60,11 +60,26 @@
:disabled? disabled?}))
promo-code-emails (set (keep (fn [o]
(get o "email"))
(get result "promo-emails")))]
(get result "promo-emails")))
drop-refresh-spam (when-let [hz-flag (-> (get result "drop-refresh-spam")
first)]
(let [disabled-apps (-> hz-flag
(get "disabled-apps")
(#(map parse-uuid %))
set)
enabled-apps (-> hz-flag
(get "enabled-apps")
(#(map parse-uuid %))
set)
default-value (get hz-flag "default-value" false)]
{:disabled-apps disabled-apps
:enabled-apps enabled-apps
:default-value default-value}))]
{:emails emails
:storage-enabled-whitelist storage-enabled-whitelist
:hazelcast hazelcast
:promo-code-emails promo-code-emails}))
:promo-code-emails promo-code-emails
:drop-refresh-spam drop-refresh-spam}))

(def queries [{:query query :transform #'transform-query-result}])

Expand Down Expand Up @@ -109,3 +124,16 @@

(defn hazelcast-disabled? []
(get-in (query-result) [:hazelcast :disabled?] false))

(defn drop-refresh-spam? [app-id]
(if-let [flag (get (query-result) :drop-refresh-spam)]
(let [{:keys [disabled-apps enabled-apps default-value]} flag]
(cond (contains? disabled-apps app-id)
false

(contains? enabled-apps app-id)
true

:else default-value))
;; Default false
false))
44 changes: 23 additions & 21 deletions server/src/instant/reactive/session.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@
Each connection has their own `session` worker, that can understand these
commands."
(:require
[lambdaisland.uri :as uri]
[instant.config :as config]
[instant.util.async :as ua]
[instant.jdbc.aurora :as aurora]
[instant.jdbc.sql :as sql]
[instant.reactive.store :as rs]
[instant.reactive.query :as rq]
[instant.db.transaction :as tx]
[instant.util.tracer :as tracer]
[clojure.main :refer [root-cause]]
[instant.db.datalog :as d]
[instant.util.json :refer [<-json]]
[instant.util.delay :as delay]
[instant.model.app :as app-model]
[instant.db.model.attr :as attr-model]
[instant.db.permissioned-transaction :as permissioned-tx]
[instant.db.pg-introspect :as pg-introspect]
[instant.db.transaction :as tx]
[instant.flags :as flags]
[instant.grouped-queue :as grouped-queue]
[instant.jdbc.aurora :as aurora]
[instant.jdbc.sql :as sql]
[instant.model.app :as app-model]
[instant.model.app-admin-token :as app-admin-token-model]
[instant.model.app-user :as app-user-model]
[instant.model.instant-user :as instant-user-model]
[instant.model.app-admin-token :as app-admin-token-model]
[instant.db.permissioned-transaction :as permissioned-tx]
[instant.model.rule :as rule-model]
[clojure.main :refer [root-cause]]
[instant.reactive.ephemeral :as eph]
[instant.reactive.query :as rq]
[instant.reactive.receive-queue :as receive-queue :refer [receive-q]]
[instant.reactive.store :as rs]
[instant.util.async :as ua]
[instant.util.delay :as delay]
[instant.util.exception :as ex]
[instant.util.json :refer [<-json]]
[instant.util.tracer :as tracer]
[instant.util.uuid :as uuid-util]
[instant.grouped-queue :as grouped-queue]
[instant.reactive.receive-queue :as receive-queue :refer [receive-q]])
[lambdaisland.uri :as uri])
(:import
(java.time Duration Instant)
(java.util.concurrent CancellationException)
(java.util.concurrent.atomic AtomicLong)
(java.time Duration Instant)))
(java.util.concurrent.atomic AtomicLong)))

;; ------
;; Setup
Expand Down Expand Up @@ -188,13 +188,15 @@
num-spam (count spam)
num-computations (count computations)
num-recomputations (count recompute-results)
computations (if config/drop-refresh-spam?
drop-spam? (flags/drop-refresh-spam? app-id)
computations (if drop-spam?
computations
recompute-results)]
(tracer/with-span! {:name "handle-refresh/send-event!"
:attributes {:num-recomputations num-recomputations
:num-spam num-spam
:num-computations num-computations}}
:num-computations num-computations
:dropped-spam? drop-spam?}}
(when (seq computations)
(rs/send-event! store-conn app-id sess-id {:op :refresh-ok
:processed-tx-id processed-tx-id
Expand Down

0 comments on commit bed51da

Please sign in to comment.