diff options
| author | 2024-07-31 16:03:34 +0200 | |
|---|---|---|
| committer | 2024-07-31 15:03:34 +0100 | |
| commit | 38f041cea1ba0cd3492f351353a29aa5b73e2731 (patch) | |
| tree | bdd055d5cf7d9c06523c694cb4abe86d220960d0 /internal/db | |
| parent | [feature] Object store custom URL (S3) (#3046) (diff) | |
| download | gotosocial-38f041cea1ba0cd3492f351353a29aa5b73e2731.tar.xz | |
[feature] Allow users to export data via the settings panel (#3140)
* [feature] Allow users to export data via the settings panel
* rename/move some stuff
Diffstat (limited to 'internal/db')
| -rw-r--r-- | internal/db/bundb/list.go | 8 | ||||
| -rw-r--r-- | internal/db/bundb/relationship.go | 5 | ||||
| -rw-r--r-- | internal/db/bundb/relationship_mute.go | 5 | ||||
| -rw-r--r-- | internal/db/list.go | 3 | ||||
| -rw-r--r-- | internal/db/relationship.go | 6 | 
5 files changed, 27 insertions, 0 deletions
| diff --git a/internal/db/bundb/list.go b/internal/db/bundb/list.go index b8391ff6d..937257ef0 100644 --- a/internal/db/bundb/list.go +++ b/internal/db/bundb/list.go @@ -106,6 +106,14 @@ func (l *listDB) GetListsForAccountID(ctx context.Context, accountID string) ([]  	return l.GetListsByIDs(ctx, listIDs)  } +func (l *listDB) CountListsForAccountID(ctx context.Context, accountID string) (int, error) { +	return l.db. +		NewSelect(). +		Table("lists"). +		Where("? = ?", bun.Ident("account_id"), accountID). +		Count(ctx) +} +  func (l *listDB) PopulateList(ctx context.Context, list *gtsmodel.List) error {  	var (  		err  error diff --git a/internal/db/bundb/relationship.go b/internal/db/bundb/relationship.go index e3a4a2c0b..69b91f161 100644 --- a/internal/db/bundb/relationship.go +++ b/internal/db/bundb/relationship.go @@ -178,6 +178,11 @@ func (r *relationshipDB) GetAccountBlocks(ctx context.Context, accountID string,  	return r.GetBlocksByIDs(ctx, blockIDs)  } +func (r *relationshipDB) CountAccountBlocks(ctx context.Context, accountID string) (int, error) { +	blockIDs, err := r.GetAccountBlockIDs(ctx, accountID, nil) +	return len(blockIDs), err +} +  func (r *relationshipDB) GetAccountFollowIDs(ctx context.Context, accountID string, page *paging.Page) ([]string, error) {  	return loadPagedIDs(&r.state.Caches.DB.FollowIDs, ">"+accountID, page, func() ([]string, error) {  		var followIDs []string diff --git a/internal/db/bundb/relationship_mute.go b/internal/db/bundb/relationship_mute.go index 94c51050d..a84aad546 100644 --- a/internal/db/bundb/relationship_mute.go +++ b/internal/db/bundb/relationship_mute.go @@ -77,6 +77,11 @@ func (r *relationshipDB) GetMute(  	)  } +func (r *relationshipDB) CountAccountMutes(ctx context.Context, accountID string) (int, error) { +	muteIDs, err := r.getAccountMuteIDs(ctx, accountID, nil) +	return len(muteIDs), err +} +  func (r *relationshipDB) getMutesByIDs(ctx context.Context, ids []string) ([]*gtsmodel.UserMute, error) {  	// Load all mutes IDs via cache loader callbacks.  	mutes, err := r.state.Caches.DB.UserMute.LoadIDs("ID", diff --git a/internal/db/list.go b/internal/db/list.go index 16a0207de..a57f0ed23 100644 --- a/internal/db/list.go +++ b/internal/db/list.go @@ -33,6 +33,9 @@ type List interface {  	// GetListsForAccountID gets all lists owned by the given accountID.  	GetListsForAccountID(ctx context.Context, accountID string) ([]*gtsmodel.List, error) +	// CountListsForAccountID counts the number of lists owned by the given accountID. +	CountListsForAccountID(ctx context.Context, accountID string) (int, error) +  	// PopulateList ensures that the list's struct fields are populated.  	PopulateList(ctx context.Context, list *gtsmodel.List) error diff --git a/internal/db/relationship.go b/internal/db/relationship.go index 5e0650fb7..ddc09d67b 100644 --- a/internal/db/relationship.go +++ b/internal/db/relationship.go @@ -179,6 +179,9 @@ type Relationship interface {  	// GetAccountBlockIDs is like GetAccountBlocks, but returns just IDs.  	GetAccountBlockIDs(ctx context.Context, accountID string, page *paging.Page) ([]string, error) +	// CountAccountBlocks counts the number of blocks owned by the given account. +	CountAccountBlocks(ctx context.Context, accountID string) (int, error) +  	// GetNote gets a private note from a source account on a target account, if it exists.  	GetNote(ctx context.Context, sourceAccountID string, targetAccountID string) (*gtsmodel.AccountNote, error) @@ -197,6 +200,9 @@ type Relationship interface {  	// GetMute returns the mute from account1 targeting account2, if it exists, or an error if it doesn't.  	GetMute(ctx context.Context, account1 string, account2 string) (*gtsmodel.UserMute, error) +	// CountAccountMutes counts the number of mutes owned by the given account. +	CountAccountMutes(ctx context.Context, accountID string) (int, error) +  	// PutMute attempts to insert or update the given account mute in the database.  	PutMute(ctx context.Context, mute *gtsmodel.UserMute) error | 
