Commit Graph

177 Commits

Author SHA1 Message Date
Conrad Hoffmann 8a40a82b96 api: delete repositories asynchronously
Currently, a request to delete a repository is blocked until the
repository is completely removed from the filesystem. When CephFS is
under load and a user deletes a large-ish repo, this can cause signicant
request latency, making the user abort the request or even timing out
completely. The context gets canceled, causing the transaction to roll
back, even though the data is eventually wiped completely from storage,
leaving users with broken repositories on their profile.

Instead, simply do the deletion from storage asynchronously, so that the
user gets instant feedback. Even though the deletion itself blocks for
potentially a long time, experience has shown that it finishes even in
case of cancellation. As such, I expect that the deletion will go
through even if the go-routine were to be aborted (e.g. by a restart of
the API).
2024-04-11 16:42:40 +02:00
Simon Ser d3ff388b65 api/graph: use core-go's s3.Enabled 2024-02-02 12:09:50 +01:00
Simon Ser 1d342a2a35 Assert error is not nil before using it
Same as d70bfd1812b8 in page.sr.ht.
2024-01-24 15:45:23 +01:00
Simon Ser 2da016a3d3 Add support for [objects]s3-insecure 2024-01-24 12:51:32 +01:00
KAAtheWise adc6fbc160 Fix repo visibility change API not working
During the upgrade to `gqlgen` version 1.17.42 a breaking change was
introduced, as `map[string]interface{}` values were changed to be type
checked in 1.17.40 (commit 74e918f9, PR
https://github.com/99designs/gqlgen/pull/2830).  As Emersion noted,
changing `OptionalString` to `Optional` fixes this.

Additionally, I replaced the "placeholder" error message with something
a bit more descriptive as a stopgap measure.
2024-01-20 15:17:44 +01:00
Simon Ser d1957c458d Fix defer cleanups 2024-01-17 19:33:34 +01:00
Simon Ser 1e779fe7aa Remove unnecessary recover calls 2024-01-17 19:24:38 +01:00
Conrad Hoffmann 4f0a8ec086 Update core-go and associated dependencies
Kudos to minio for breaking changes in a patch release...
2023-11-23 11:20:38 +01:00
Simon Ser 4de526de53 api/graph: fix invalid @access directive in WebhookEvent enum
Fixes the following schema error:

    Directive access is not applicable on ENUM_VALUE.
2023-10-24 13:27:01 +02:00
Conrad Hoffmann ee7701a9eb api: fix timezone issue in repo pagination
As lists of repositories are sorted and paginated by their "updated"
timestamp, a cursor carries such a timestamp, so that the next query can
pick up where the last one left off. However, the passing of this
timestamp is broken on systems that do not run on UTC.

Go translates time values to the system's timezone, but this timezone
information gets lost when handing the value to postgres, presumably
because the column type is "timestamp without time zone".

Avoid the issue by converting the parsed timestamp back to UTC right
away.
2023-08-16 11:19:11 +02:00
Conrad Hoffmann a063090a89 api: micro-second resolution for repo pagination
Lists of repositories are sorted and paginated based on their "updated"
timestamp. However, fractional seconds are discarded. This can cause
issues with repositories that have been updated in the same second (e.g.
by running a script).

This commit leverages the micro-second resolution of the timestamp in
postgres to make this case not impossible, yet highly unlikely.
2023-08-16 11:19:10 +02:00
Conrad Hoffmann 490163fcd1 api: fix join for repositories resolver
The left join used for listing repositories has a curious issue: if you
grant access to a private repo to x people, where x > 1, this repo will
show up x times if you list your own repos via GraphQL.

To fix, add an additional join restriction: we are only interested in
ACLs for the calling user. This makes sure that at most one ACL will be
returned, hence avoiding duplicate repositories.
2023-08-16 11:18:43 +02:00
Thorben Günther e1244429d4 api/acls: Error out early
This simplifies the database query and is more consistent with how
tracker and list acl queries behave.
2023-07-07 10:10:38 +02:00
Adnan Maolood 24eb656eb7 Move go.mod to root
Also update go.mod to Go 1.16.
2023-06-01 12:26:45 +02:00
Umar Getagazov 3039891a15 api: prevent repos with ACL from being duplicated
Only join with access entries if the second condition of the OR
condition in the WHERE clause (i.e. `repo.visibility = 'PUBLIC') is
false, which prevents WHERE from short-circuiting for every row.
2023-03-13 13:01:48 +01:00
Adnan Maolood be2eda013d api: Upgrade go-git 2022-12-19 13:14:15 +01:00
Adnan Maolood 03671cc4a4 api/graph: Avoid race condition when cloning repos 2022-11-10 11:23:39 +01:00
Adnan Maolood fe9d0d9ab3 api/graph: Ensure files are closed after creation 2022-11-10 11:23:38 +01:00
Conrad Hoffmann d9d750669d api: rename accessControlList() to acls()
To be consistent with other services (e.g. todo.sr.ht).
2022-11-07 12:18:53 +01:00
Conrad Hoffmann b626d9177f api: expose current user's repository access level
For a given repository, the `access` attribute contains the AccessMode
that applies to the current user.
2022-11-07 12:18:47 +01:00
Thorben Günther e02b460f84 api: Rename user webhook mutations
Conform with terminology of other services.
Make deleteUserWebhook non-nullable.
2022-11-07 12:18:24 +01:00
Drew DeVault 4436def286 Implement user account deletion 2022-11-01 14:01:38 +01:00
Adnan Maolood 1272ef2588 gitsrht: Use canonical user IDs
Update user IDs across git.sr.ht to match those of meta.sr.ht.
2022-10-26 10:42:56 +02:00
Drew DeVault ce1c1d8094 API: upgrade gqlgen 2022-10-20 14:45:25 +02:00
Thorben Günther 483a560411 api/webhooks: Add missing default case 2022-07-06 10:30:55 +02:00
Adnan Maolood 4558b995c2 Update core-go 2022-05-30 14:19:01 +02:00
Adnan Maolood b54049b3d9 api/graph: Fix webhook delivery name 2022-05-30 13:37:43 +02:00
Adnan Maolood ad82b3b38c api/server: Register @private directive 2022-04-18 11:13:59 +02:00
Drew DeVault be6100f36c gqlgen.yml: rename generated file 2022-03-24 14:39:07 +01:00
Drew DeVault 4439008384 api: update gqlgen 2022-03-24 11:34:19 +01:00
Adnan Maolood f4580eca83 api/graph: Improve error handling 2022-03-24 11:19:04 +01:00
Adnan Maolood ad42bf4448 gitsrht: Store visibility as enum instead of varchar
Add a 'visibility' enum type to the database and use it for the
repository.visibility column.

This required changes to scm.sr.ht code. Instead of updating scm.sr.ht,
most of the scm.sr.ht code that git.sr.ht uses was moved to git.sr.ht.
2022-03-14 09:59:12 +01:00
Adnan Maolood 42c0008108 api/loaders: Add RepositoriesByOwnerIDRepoName loader 2022-02-17 14:47:37 +01:00
Adnan Maolood aaa1f6f287 api/loaders: Refactor RepositoriesByOwnerRepoName 2022-02-17 14:47:36 +01:00
Adnan Maolood 4e8fd8c296 api: Handle clone errors
This adds two new columns to the database: clone_status and clone_error,
which are used to store the clone status as well as any error that
occurs. The error is then displayed to the user in the frontend.
2022-02-17 14:45:57 +01:00
Adnan Maolood c3727531fd api/graph/schema.graphqls: Clarify Entity docstrings 2022-02-17 14:43:25 +01:00
Adnan Maolood d3869ff5f2 api/loaders: Remove unused loader 2022-02-17 14:43:24 +01:00
Adnan Maolood a15657f955 api/webhooks: Move middlewares to core-go 2022-02-17 14:43:06 +01:00
Adnan Maolood ffb36c00d0 api/graph: Delete artifacts upon repository deletion
Upon deleting a repository, gather a list of all the artifacts
associated with it and schedule their deletion in a background task.

Fixes: https://todo.sr.ht/~sircmpwn/git.sr.ht/356
2022-02-15 13:12:07 +01:00
Adnan Maolood 9d12b36978 api/graph/repos: Rename from clones 2022-02-15 13:12:06 +01:00
Adnan Maolood 052afbaeb7 Drop source_repo_id and upstream_uri from repository 2022-02-15 13:12:06 +01:00
Drew DeVault 136bd3848a API: createRepository: create git-daemon-export-ok
This file is necessary for git clones to work for public and unlisted
repositories.
2022-02-15 09:11:22 +01:00
Adnan Maolood fb3f415734 api/clones: Unset clone_in_progress on panic 2022-02-14 16:00:01 +01:00
Adnan Maolood 47ec8529b4 api/clones: Timeout clones after 10 minutes 2022-02-14 15:42:10 +01:00
Adnan Maolood 91eb5822e8 gitsrht: Indicate if a clone is in progress 2022-02-14 15:42:10 +01:00
Adnan Maolood 115487d546 api/graph: Execute webhook queries before deletion
Execute GraphQL webhook queries after the repository has been deleted
from the database, but before the files have been removed from the
filesystem. This prevents filesystem errors during query execution.

We don't need to execute the query before the repository is deleted from
the database since all the information we need from the database has
been retrieved.

References: https://todo.sr.ht/~sircmpwn/sr.ht/301
2022-02-14 15:42:10 +01:00
Drew DeVault e5bf52f988 API: Switch to SourceHut go-git tree 2022-02-14 15:42:10 +01:00
Adnan Maolood 188abe70fa api/graph: Do clones in the background 2022-02-14 15:42:10 +01:00
Adnan Maolood 8806cc14f6 api/graph: Add HEAD field to RepoInput type
Add a HEAD field to the RepoInput type to allow setting the default
branch name with the updateRepository GraphQL mutation. Also modify the
frontend to use the HEAD field for the repository settings page.

Implements: https://todo.sr.ht/~sircmpwn/git.sr.ht/358
2022-02-14 15:42:10 +01:00
Drew DeVault e99eddb3c0 API: Update go.mod, style fixes 2022-02-14 15:42:10 +01:00