From 38f041cea1ba0cd3492f351353a29aa5b73e2731 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:03:34 +0200 Subject: [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 --- internal/db/bundb/list.go | 8 ++++++++ internal/db/bundb/relationship.go | 5 +++++ internal/db/bundb/relationship_mute.go | 5 +++++ 3 files changed, 18 insertions(+) (limited to 'internal/db/bundb') 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", -- cgit v1.3