From dba533a14bd4f3509556163790ab27623d694b29 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Sun, 11 Oct 2020 08:32:55 -0700 Subject: [PATCH] temporarily disable actually deleting Followers on AP Delete requests mastodon.social sends Deletes for every Bridgy Fed account, all at basically the same time, and we have many Follower objects, so we have to do this table scan for each one, so the requests take a long time and end up spawning extra App Engine instances that we get billed for. and the Delete requests are almost never for followers we have. TODO: revisit this and do it right. --- .gitignore | 1 + README.md | 4 ++-- activitypub.py | 21 +++++++++++++++------ app.yaml | 4 ++++ tests/test_activitypub.py | 3 ++- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 0faff18..c52a6f7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ datastore.dat* /l /local* private_notes +service_account_creds.json TAGS diff --git a/README.md b/README.md index 77fa021..9b3e3b5 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Development You'll need Python 3. Install the [Google Cloud SDK](https://cloud.google.com/sdk/gcloud/) (aka `gcloud`) with the `gcloud-appengine-python` and `gcloud-appengine-python-extras` [components](https://cloud.google.com/sdk/docs/components#additional_components). Then, run: ```sh -python3 -m venv local3 -source local3/bin/activate +python3 -m venv local +source local/bin/activate pip install -r requirements.txt ``` diff --git a/activitypub.py b/activitypub.py index fc63a0a..916114f 100644 --- a/activitypub.py +++ b/activitypub.py @@ -135,12 +135,21 @@ class InboxHandler(common.Handler): return self.undo_follow(self.redirect_unwrap(activity)) elif type == 'Delete': id = obj.get('id') - if isinstance(id, str): - # assume this is an actor - # https://github.com/snarfed/bridgy-fed/issues/63 - for key in Follower.query().iter(keys_only=True): - if key.id().split(' ')[-1] == id: - key.delete() + + # !!! temporarily disabled actually deleting Followers below because + # mastodon.social sends Deletes for every Bridgy Fed account, all at + # basically the same time, and we have many Follower objects, so we + # have to do this table scan for each one, so the requests take a + # long time and end up spawning extra App Engine instances that we + # get billed for. and the Delete requests are almost never for + # followers we have. TODO: revisit this and do it right. + + # if isinstance(id, str): + # # assume this is an actor + # # https://github.com/snarfed/bridgy-fed/issues/63 + # for key in Follower.query().iter(keys_only=True): + # if key.id().split(' ')[-1] == id: + # key.delete() return # fetch actor if necessary so we have name, profile photo, etc diff --git a/app.yaml b/app.yaml index 21fb2f4..f4eb195 100644 --- a/app.yaml +++ b/app.yaml @@ -1,7 +1,11 @@ # https://cloud.google.com/appengine/docs/standard/python/config/appref # application: bridgy-federated + +# pycrypto doesn't support python 3.8 (due to time.clock). should switch to +# pycryptodome. runtime: python37 + # default_expiration: 1h # https://cloud.google.com/appengine/docs/standard/python3/runtime#entrypoint_best_practices diff --git a/tests/test_activitypub.py b/tests/test_activitypub.py index 3d968f9..d5e6501 100644 --- a/tests/test_activitypub.py +++ b/tests/test_activitypub.py @@ -422,4 +422,5 @@ class ActivityPubTest(testutil.TestCase): body=json_dumps(DELETE).encode()) self.assertEqual(200, got.status_int) - self.assertEqual([other], Follower.query().fetch()) + # TODO: bring back + # self.assertEqual([other], Follower.query().fetch())