summaryrefslogtreecommitdiff
path: root/internal/cache
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cache')
-rw-r--r--internal/cache/account.go12
-rw-r--r--internal/cache/status.go14
-rw-r--r--internal/cache/status_test.go26
-rw-r--r--internal/cache/util.go31
4 files changed, 70 insertions, 13 deletions
diff --git a/internal/cache/account.go b/internal/cache/account.go
index a71274d1c..ac67b5d07 100644
--- a/internal/cache/account.go
+++ b/internal/cache/account.go
@@ -103,16 +103,16 @@ func copyAccount(account *gtsmodel.Account) *gtsmodel.Account {
Fields: account.Fields,
Note: account.Note,
NoteRaw: account.NoteRaw,
- Memorial: account.Memorial,
+ Memorial: copyBoolPtr(account.Memorial),
MovedToAccountID: account.MovedToAccountID,
+ Bot: copyBoolPtr(account.Bot),
CreatedAt: account.CreatedAt,
UpdatedAt: account.UpdatedAt,
- Bot: account.Bot,
Reason: account.Reason,
- Locked: account.Locked,
- Discoverable: account.Discoverable,
+ Locked: copyBoolPtr(account.Locked),
+ Discoverable: copyBoolPtr(account.Discoverable),
Privacy: account.Privacy,
- Sensitive: account.Sensitive,
+ Sensitive: copyBoolPtr(account.Sensitive),
Language: account.Language,
StatusFormat: account.StatusFormat,
URI: account.URI,
@@ -131,7 +131,7 @@ func copyAccount(account *gtsmodel.Account) *gtsmodel.Account {
SensitizedAt: account.SensitizedAt,
SilencedAt: account.SilencedAt,
SuspendedAt: account.SuspendedAt,
- HideCollections: account.HideCollections,
+ HideCollections: copyBoolPtr(account.HideCollections),
SuspensionOrigin: account.SuspensionOrigin,
}
}
diff --git a/internal/cache/status.go b/internal/cache/status.go
index 7e3d85960..f3cbce779 100644
--- a/internal/cache/status.go
+++ b/internal/cache/status.go
@@ -102,9 +102,9 @@ func copyStatus(status *gtsmodel.Status) *gtsmodel.Status {
Mentions: nil,
EmojiIDs: status.EmojiIDs,
Emojis: nil,
+ Local: copyBoolPtr(status.Local),
CreatedAt: status.CreatedAt,
UpdatedAt: status.UpdatedAt,
- Local: status.Local,
AccountID: status.AccountID,
Account: nil,
AccountURI: status.AccountURI,
@@ -119,15 +119,15 @@ func copyStatus(status *gtsmodel.Status) *gtsmodel.Status {
BoostOfAccount: nil,
ContentWarning: status.ContentWarning,
Visibility: status.Visibility,
- Sensitive: status.Sensitive,
+ Sensitive: copyBoolPtr(status.Sensitive),
Language: status.Language,
CreatedWithApplicationID: status.CreatedWithApplicationID,
- Federated: status.Federated,
- Boostable: status.Boostable,
- Replyable: status.Replyable,
- Likeable: status.Likeable,
ActivityStreamsType: status.ActivityStreamsType,
Text: status.Text,
- Pinned: status.Pinned,
+ Pinned: copyBoolPtr(status.Pinned),
+ Federated: copyBoolPtr(status.Federated),
+ Boostable: copyBoolPtr(status.Boostable),
+ Replyable: copyBoolPtr(status.Replyable),
+ Likeable: copyBoolPtr(status.Likeable),
}
}
diff --git a/internal/cache/status_test.go b/internal/cache/status_test.go
index 882e92be5..8b0621182 100644
--- a/internal/cache/status_test.go
+++ b/internal/cache/status_test.go
@@ -72,6 +72,32 @@ func (suite *StatusCacheTestSuite) TestStatusCache() {
}
}
+func (suite *StatusCacheTestSuite) TestBoolPointerCopying() {
+ originalStatus := suite.data["local_account_1_status_1"]
+
+ // mark the status as pinned + cache it
+ pinned := true
+ originalStatus.Pinned = &pinned
+ suite.cache.Put(originalStatus)
+
+ // retrieve it
+ cachedStatus, ok := suite.cache.GetByID(originalStatus.ID)
+ if !ok {
+ suite.FailNow("status wasn't retrievable from cache")
+ }
+
+ // we should be able to change the original status values + cached
+ // values independently since they use different pointers
+ suite.True(*cachedStatus.Pinned)
+ *originalStatus.Pinned = false
+ suite.False(*originalStatus.Pinned)
+ suite.True(*cachedStatus.Pinned)
+ *originalStatus.Pinned = true
+ *cachedStatus.Pinned = false
+ suite.True(*originalStatus.Pinned)
+ suite.False(*cachedStatus.Pinned)
+}
+
func TestStatusCache(t *testing.T) {
suite.Run(t, &StatusCacheTestSuite{})
}
diff --git a/internal/cache/util.go b/internal/cache/util.go
new file mode 100644
index 000000000..48204b259
--- /dev/null
+++ b/internal/cache/util.go
@@ -0,0 +1,31 @@
+/*
+ GoToSocial
+ Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package cache
+
+// copyBoolPtr returns a bool pointer with the same value as the pointer passed into it.
+//
+// Useful when copying things from the cache to a caller.
+func copyBoolPtr(in *bool) *bool {
+ if in == nil {
+ return nil
+ }
+ b := new(bool)
+ *b = *in
+ return b
+}