Commit graph

8296 commits

Author SHA1 Message Date
Wesley Aptekar-Cassels
2a5f722f6e Optimize add/remove book statuses task queries
The queries as they previously existed required joining together 12
different tables, which is extremely expensive. Splitting it into four
queries means that the individual queries can effectively use the
indexes we have, and should be very fast no matter how many statuses are
in the database.

Removing the .distinct() call is fine, since we're adding them to a set
in Redis anyways, which will take care of the duplicates.

It's a bit ugly that we now make four separate calls to Redis (this
might result in things being slightly slower in cases where there are an
extremely small number of statuses), but doing things differently would
result in significantly more surgery to the existing code, so I've opted
to avoid that for the moment.

Fixes: #2725
2023-03-09 15:26:03 -05:00
Wesley Aptekar-Cassels
cc610372ca Fix dbshell command
dbshell needs to be run in a already-running container, thus exec rather
than run is the correct docker-compose command.
2023-03-09 02:02:56 -05:00
Wesley Aptekar-Cassels
56243f6529 Optimize HomeStream.get_audience
This splits HomeStream.get_audience into two separate database queries,
in order to more effectively take advantage of the indexes we have.
Combining the user ID query and the user following query means that
Postgres isn't able to use the index we have on the userfollows table.

The query planner claims that the userfollows query should be about 20
times faster than it was previously, and the id query should take a
negligible amount of time, since it's selecting a single item by primary
key.

We don't need to worry about duplicates, since there is a constraint
preventing a user from following themself.

Fixes: #2720
2023-03-09 00:50:24 -05:00
Wesley Aptekar-Cassels
23698dafe5 Change get_audience to return list of user IDs
This will make it simpler to implement various optimizations.
2023-03-09 00:50:24 -05:00
Wesley Aptekar-Cassels
41e14bdfaf Change unread_by_status_type_id to take user ID
Same reason as in prior commit.
2023-03-09 00:50:24 -05:00
Wesley Aptekar-Cassels
653e8ee81b Change unread_id to take user ID
Same reason as described in the prior commit.
2023-03-09 00:50:24 -05:00
Wesley Aptekar-Cassels
5446869c38 Change stream_id to take user ID
Anywhere we have a user object, we can easily get the user ID in the
caller, and this will allow us more flexibility in the future to
implement optimizations that involve knowing a user ID without querying
the database for the user object.
2023-03-09 00:50:16 -05:00
Mouse Reeve
e4edef03c5
Merge pull request #2721 from verymilan/verymilan-patch-1
fix typo in systemd example
2023-03-08 18:39:05 -08:00
Wesley Aptekar-Cassels
50a81bdfdd Change CSV export to buffer instead of streaming
The idea behind a streaming CSV export was to reduce the amount of
memory used, by avoiding building the entire CSV file in memory before
sending it to the client. However, it didn't work out this way in
practice: the query objects that were created to represent each line
caused Postgres to generate a very large (~200MB on bookwyrm.social)
temp file, not to mention the memory being used by the Query object
likely being similar to, if not larger than that used by the finalized
CSV row.

While we should in the long term run our CSV exports as a Celery task,
this change should allow CSV exports to work on large servers without
causing disk-space problems.

Fixes: #2157
2023-03-08 21:37:56 -05:00
Mouse Reeve
5c109a2566
Merge branch 'main' into celery-env-vars 2023-03-08 18:37:03 -08:00
Mouse Reeve
2f737efeff
Merge pull request #2709 from WesleyAC/improve-polling-backoff
Improve polling algorithm
2023-03-08 18:36:19 -08:00
Wesley Aptekar-Cassels
4af4f30cde Broaden except section for HTTP request in dashboard
get_data can return exceptions other than ConnectorException, and when
it does, we want to simply not show the update section, rather than
crashing.

Related: #2717
2023-03-08 21:32:41 -05:00
Chris Moultrie
86675ee944
Example Settings and run black 2023-03-08 14:48:04 -05:00
Milan
a6bc53a936
fix typo in systemd example
...which prevented imports from running
2023-03-08 19:58:58 +01:00
Wesley Aptekar-Cassels
9cbff312a5 Ignore Celery task results
Since we don't use the results of our Celery tasks (all of them return
None implicitly), it's prudent to set the ignore_result flag, for a
potential performance improvement. See the Celery docs for details [1].

We could do this with the global CELERY_IGNORE_RESULT setting, but it
offers more flexibility if we want to use task results in the future to
set it on a per-task basis.

[1]: https://docs.celeryq.dev/en/stable/userguide/tasks.html#ignore-results-you-don-t-want
2023-03-08 02:12:13 -05:00
Mouse Reeve
c3109f1238
Merge branch 'main' into improve-polling-backoff 2023-03-07 13:57:00 -08:00
Mouse Reeve
3c57797852
Merge branch 'main' into portable-hashbangs 2023-03-07 13:56:44 -08:00
Mouse Reeve
1350e91971
Merge branch 'main' into book-edit-form-validation-notification 2023-03-07 13:56:23 -08:00
Mouse Reeve
00666c4f52
Merge pull request #2711 from bookwyrm-social/fix/reorder-head-migration
Reorder head migration
2023-03-07 13:56:04 -08:00
Christof Dorner
ee0a89faf2 Reorder head migration 2023-03-07 22:31:58 +01:00
Christof Dorner
bc0b291d36 Show notification banner on top of form when book failed to update 2023-03-07 21:58:12 +01:00
Wesley Aptekar-Cassels
26e34ddffa Add env vars for celery concurrency and time limit 2023-03-07 13:52:02 -05:00
Wesley Aptekar-Cassels
abb5dc857e Use more portable shebang for dev scripts
/bin/bash, while common, is not part of the unix standard, and does not
exist on some operating systems (such as NixOS). /usr/bin/env, on the
other hand, is standardized, and thus should exist on all systems.
2023-03-07 13:39:18 -05:00
Wesley Aptekar-Cassels
43ad3d0c15 Improve polling algorithm
The existing polling code had a few problems:

* It started the timer for a new request when the first request was
  sent, rather than when a response was received.
* It increased the delay regardless of whether the response was a
  success or a failure.

This commit changes it to a more standard exponential backoff system,
where it starts with a 5 minute ± 30 second delay, and uses that same
delay until it hits an error, at which point the delay is increased by
10%. Once it receives a successful response again, the delay is reset to
the default.

I suspect this should be nicer on the server, since it avoids the
initial sending of many requests. After about half an hour of leaving
the page open, the request rate for this new code will be higher than
that of the old code, so it's possible that this may cause problems, but
I think that a five-minute request frequency should be pretty reasonable.
2023-03-07 13:15:52 -05:00
Mouse Reeve
05a303ea18
Merge pull request #2690 from bookwyrm-social/link-domain-notifications
Create notifications for link domains that need approval
2023-03-07 08:43:14 -08:00
Mouse Reeve
1612217eaa
Merge pull request #2696 from bookwyrm-social/chronological-pagination
Only use chronological pagination sometimes
2023-03-07 08:42:43 -08:00
Christof Dorner
9ca9883e0b Enable finding existing hashtags case-insensitive
We should store hashtags case-sensitive, but ensures that an existing
hashtag with different case are found and re-used. for example,
an existing #BookWyrm hashtag will be found and used even if the
status content is using #bookwyrm.
2023-03-07 13:16:45 +01:00
Christof Dorner
f3334b1550 Render hashtag links with data-mention="hashtag" attribute 2023-03-07 13:16:45 +01:00
Christof Dorner
276b255f32 Post-process status.content field to change hashtag URLs
Since the status content already contains rendered HTML when we receive an
ActivityPub inbox message it contains links to the mentioned hashtags on the
originating instance.

To fix this on the receiving instance we need to post-process the status content
after successfully storing the status and its many-to-many fields (the one we're
is the `mention_hashtags`). Post-processing means that we run a regex against the
content to find the anchor tags linking to the originating hashtag and replace the
`href` attribute with the URL to the hashtag page on the receiving (local) instance.
2023-03-07 13:16:45 +01:00
Christof Dorner
0fd49d2aea Mark Hashtag.name field as deduplication field
This ensures that when an existing hashtag comes in through ActivityPub federation,
it correctly finds the local one, instead of creating duplicate hashtags.
2023-03-07 13:11:27 +01:00
Christof Dorner
e8a306437f Reorder migrations to add hashtag one at the end 2023-03-07 13:11:27 +01:00
Christof Dorner
824d4207dc Try and fix a flaky test
Same case as with #2496, for some reason the URL to the cover just ends with `test.jpg`
2023-03-07 12:59:32 +01:00
Christof Dorner
499aace9fb Add basic view listing activities from a given hashtag 2023-03-07 12:59:32 +01:00
Christof Dorner
11640f986e Import hashtags from activitypub statuses 2023-03-07 12:59:31 +01:00
Christof Dorner
ba0fcccfc5 Link hashtags in status content 2023-03-07 12:55:36 +01:00
Christof Dorner
c68304a99b Parse hashtags and store them in CreateStatus view 2023-03-07 12:55:36 +01:00
Mouse Reeve
c402433587
Merge pull request #2683 from bookwyrm-social/resolve-local-tasks-synchronously
Attempt to complete inbox requests synchronously
2023-03-06 19:20:16 -08:00
Chris Moultrie
f8e60f4a89
Enable Azure BlobStorage as an alternative to AWS S3
This adds a new storage backend for Azure BlobStorage, I'm running this patch in Azure Kubernetes
hosting all my assets in Azure BlobStorage and it's been stable enough I thought I should commit
this back upstream.
2023-03-05 12:08:16 -05:00
André Jaenisch
9c92ba1698
Add attributes to images to hint async load
This was suggested on Matrix a while ago but I only found the time now to move forward with it.

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
2023-03-01 14:14:42 +01:00
Rajat Dwivedi
7caa60dba5
Improving Feed link UI colours 2023-02-27 20:14:32 +05:30
Hugh Rundle
66ce298001
Merge pull request #2657 from chris-y/totp-window
Expand TOTP validity window

This changes the default window to allow 2 codes (60 seconds) on either side. Admins can change this by setting a different `TWO_FACTOR_LOGIN_VALIDITY_WINDOW` value in `.env`
2023-02-27 18:46:53 +11:00
Hugh Rundle
bba0d09fa4
Merge branch 'main' into totp-window 2023-02-27 18:21:39 +11:00
Hugh Rundle
3a67727a9a
Merge pull request #2638 from Giebisch/page-range
Page Range
2023-02-27 17:39:42 +11:00
Christof Dorner
d1110630db Use chronological pagination on user profile activity lists 2023-02-26 11:24:00 +01:00
Mouse Reeve
99fc2b7a36 Only use chronological pagination sometimes
The timeline uses chronological buttons, but other paginated pages do
not (by default). This also reversed the chronology.
2023-02-25 15:56:58 -08:00
Christof Dorner
233cf809dd
Merge pull request #2694 from kangangi/replace_next_previous
Replace Next and Previous with Older and Newer
2023-02-25 22:34:05 +01:00
wanjiku
b4e388a975 Replace Next and Previous with Older and Newer 2023-02-24 11:11:55 +03:00
Giebisch
43fe433133 Quotation same start and endposition 2023-02-23 18:40:20 +01:00
Mouse Reeve
268946a77c Adds missing template and migration files 2023-02-22 10:46:01 -08:00
Mouse Reeve
2470a0fd1c Create notifications for link domains that need approval 2023-02-22 10:20:07 -08:00