| 
									
										
										
										
											2023-03-12 16:00:57 +01:00
										 |  |  | // GoToSocial | 
					
						
							|  |  |  | // Copyright (C) GoToSocial Authors admin@gotosocial.org | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // 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/>. | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | package cache | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"codeberg.org/gruf/go-cache/v3/result" | 
					
						
							| 
									
										
										
										
											2023-03-08 13:57:41 +01:00
										 |  |  | 	"codeberg.org/gruf/go-cache/v3/ttl" | 
					
						
							| 
									
										
										
										
											2022-12-14 09:55:36 +00:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/cache/domain" | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/config" | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type GTSCaches interface { | 
					
						
							|  |  |  | 	// Init will initialize all the gtsmodel caches in this collection. | 
					
						
							|  |  |  | 	// NOTE: the cache MUST NOT be in use anywhere, this is not thread-safe. | 
					
						
							|  |  |  | 	Init() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Start will attempt to start all of the gtsmodel caches, or panic. | 
					
						
							|  |  |  | 	Start() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Stop will attempt to stop all of the gtsmodel caches, or panic. | 
					
						
							|  |  |  | 	Stop() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Account provides access to the gtsmodel Account database cache. | 
					
						
							|  |  |  | 	Account() *result.Cache[*gtsmodel.Account] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Block provides access to the gtsmodel Block (account) database cache. | 
					
						
							|  |  |  | 	Block() *result.Cache[*gtsmodel.Block] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-14 09:55:36 +00:00
										 |  |  | 	// DomainBlock provides access to the domain block database cache. | 
					
						
							|  |  |  | 	DomainBlock() *domain.BlockCache | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Emoji provides access to the gtsmodel Emoji database cache. | 
					
						
							|  |  |  | 	Emoji() *result.Cache[*gtsmodel.Emoji] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// EmojiCategory provides access to the gtsmodel EmojiCategory database cache. | 
					
						
							|  |  |  | 	EmojiCategory() *result.Cache[*gtsmodel.EmojiCategory] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Mention provides access to the gtsmodel Mention database cache. | 
					
						
							|  |  |  | 	Mention() *result.Cache[*gtsmodel.Mention] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-03 23:02:23 +00:00
										 |  |  | 	// Media provides access to the gtsmodel Media database cache. | 
					
						
							|  |  |  | 	Media() *result.Cache[*gtsmodel.MediaAttachment] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	// Notification provides access to the gtsmodel Notification database cache. | 
					
						
							|  |  |  | 	Notification() *result.Cache[*gtsmodel.Notification] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-10 15:19:05 +01:00
										 |  |  | 	// Report provides access to the gtsmodel Report database cache. | 
					
						
							|  |  |  | 	Report() *result.Cache[*gtsmodel.Report] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	// Status provides access to the gtsmodel Status database cache. | 
					
						
							|  |  |  | 	Status() *result.Cache[*gtsmodel.Status] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Tombstone provides access to the gtsmodel Tombstone database cache. | 
					
						
							|  |  |  | 	Tombstone() *result.Cache[*gtsmodel.Tombstone] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// User provides access to the gtsmodel User database cache. | 
					
						
							|  |  |  | 	User() *result.Cache[*gtsmodel.User] | 
					
						
							| 
									
										
										
										
											2023-03-08 13:57:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Webfinger | 
					
						
							|  |  |  | 	Webfinger() *ttl.Cache[string, string] | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NewGTS returns a new default implementation of GTSCaches. | 
					
						
							|  |  |  | func NewGTS() GTSCaches { | 
					
						
							|  |  |  | 	return >sCaches{} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type gtsCaches struct { | 
					
						
							|  |  |  | 	account       *result.Cache[*gtsmodel.Account] | 
					
						
							|  |  |  | 	block         *result.Cache[*gtsmodel.Block] | 
					
						
							| 
									
										
										
										
											2022-12-14 09:55:36 +00:00
										 |  |  | 	domainBlock   *domain.BlockCache | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	emoji         *result.Cache[*gtsmodel.Emoji] | 
					
						
							|  |  |  | 	emojiCategory *result.Cache[*gtsmodel.EmojiCategory] | 
					
						
							| 
									
										
										
										
											2023-03-03 23:02:23 +00:00
										 |  |  | 	media         *result.Cache[*gtsmodel.MediaAttachment] | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	mention       *result.Cache[*gtsmodel.Mention] | 
					
						
							|  |  |  | 	notification  *result.Cache[*gtsmodel.Notification] | 
					
						
							| 
									
										
										
										
											2023-01-10 15:19:05 +01:00
										 |  |  | 	report        *result.Cache[*gtsmodel.Report] | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	status        *result.Cache[*gtsmodel.Status] | 
					
						
							|  |  |  | 	tombstone     *result.Cache[*gtsmodel.Tombstone] | 
					
						
							|  |  |  | 	user          *result.Cache[*gtsmodel.User] | 
					
						
							| 
									
										
										
										
											2023-03-08 13:57:41 +01:00
										 |  |  | 	webfinger     *ttl.Cache[string, string] | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) Init() { | 
					
						
							|  |  |  | 	c.initAccount() | 
					
						
							|  |  |  | 	c.initBlock() | 
					
						
							|  |  |  | 	c.initDomainBlock() | 
					
						
							|  |  |  | 	c.initEmoji() | 
					
						
							|  |  |  | 	c.initEmojiCategory() | 
					
						
							| 
									
										
										
										
											2023-03-03 23:02:23 +00:00
										 |  |  | 	c.initMedia() | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	c.initMention() | 
					
						
							|  |  |  | 	c.initNotification() | 
					
						
							| 
									
										
										
										
											2023-01-10 15:19:05 +01:00
										 |  |  | 	c.initReport() | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	c.initStatus() | 
					
						
							|  |  |  | 	c.initTombstone() | 
					
						
							|  |  |  | 	c.initUser() | 
					
						
							| 
									
										
										
										
											2023-03-08 13:57:41 +01:00
										 |  |  | 	c.initWebfinger() | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) Start() { | 
					
						
							|  |  |  | 	tryUntil("starting gtsmodel.Account cache", 5, func() bool { | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 		return c.account.Start(config.GetCacheGTSAccountSweepFreq()) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	tryUntil("starting gtsmodel.Block cache", 5, func() bool { | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 		return c.block.Start(config.GetCacheGTSBlockSweepFreq()) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	tryUntil("starting gtsmodel.DomainBlock cache", 5, func() bool { | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 		return c.domainBlock.Start(config.GetCacheGTSDomainBlockSweepFreq()) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	tryUntil("starting gtsmodel.Emoji cache", 5, func() bool { | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 		return c.emoji.Start(config.GetCacheGTSEmojiSweepFreq()) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	tryUntil("starting gtsmodel.EmojiCategory cache", 5, func() bool { | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 		return c.emojiCategory.Start(config.GetCacheGTSEmojiCategorySweepFreq()) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2023-03-03 23:02:23 +00:00
										 |  |  | 	tryUntil("starting gtsmodel.MediaAttachment cache", 5, func() bool { | 
					
						
							|  |  |  | 		return c.media.Start(config.GetCacheGTSMediaSweepFreq()) | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	tryUntil("starting gtsmodel.Mention cache", 5, func() bool { | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 		return c.mention.Start(config.GetCacheGTSMentionSweepFreq()) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	tryUntil("starting gtsmodel.Notification cache", 5, func() bool { | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 		return c.notification.Start(config.GetCacheGTSNotificationSweepFreq()) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2023-01-10 15:19:05 +01:00
										 |  |  | 	tryUntil("starting gtsmodel.Report cache", 5, func() bool { | 
					
						
							|  |  |  | 		return c.report.Start(config.GetCacheGTSReportSweepFreq()) | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	tryUntil("starting gtsmodel.Status cache", 5, func() bool { | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 		return c.status.Start(config.GetCacheGTSStatusSweepFreq()) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	tryUntil("starting gtsmodel.Tombstone cache", 5, func() bool { | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 		return c.tombstone.Start(config.GetCacheGTSTombstoneSweepFreq()) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	tryUntil("starting gtsmodel.User cache", 5, func() bool { | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 		return c.user.Start(config.GetCacheGTSUserSweepFreq()) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2023-03-08 13:57:41 +01:00
										 |  |  | 	tryUntil("starting gtsmodel.Webfinger cache", 5, func() bool { | 
					
						
							|  |  |  | 		return c.webfinger.Start(config.GetCacheGTSWebfingerSweepFreq()) | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) Stop() { | 
					
						
							|  |  |  | 	tryUntil("stopping gtsmodel.Account cache", 5, c.account.Stop) | 
					
						
							|  |  |  | 	tryUntil("stopping gtsmodel.Block cache", 5, c.block.Stop) | 
					
						
							|  |  |  | 	tryUntil("stopping gtsmodel.DomainBlock cache", 5, c.domainBlock.Stop) | 
					
						
							|  |  |  | 	tryUntil("stopping gtsmodel.Emoji cache", 5, c.emoji.Stop) | 
					
						
							|  |  |  | 	tryUntil("stopping gtsmodel.EmojiCategory cache", 5, c.emojiCategory.Stop) | 
					
						
							| 
									
										
										
										
											2023-03-03 23:02:23 +00:00
										 |  |  | 	tryUntil("stopping gtsmodel.MediaAttachment cache", 5, c.media.Stop) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	tryUntil("stopping gtsmodel.Mention cache", 5, c.mention.Stop) | 
					
						
							|  |  |  | 	tryUntil("stopping gtsmodel.Notification cache", 5, c.notification.Stop) | 
					
						
							| 
									
										
										
										
											2023-01-10 15:19:05 +01:00
										 |  |  | 	tryUntil("stopping gtsmodel.Report cache", 5, c.report.Stop) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	tryUntil("stopping gtsmodel.Status cache", 5, c.status.Stop) | 
					
						
							|  |  |  | 	tryUntil("stopping gtsmodel.Tombstone cache", 5, c.tombstone.Stop) | 
					
						
							|  |  |  | 	tryUntil("stopping gtsmodel.User cache", 5, c.user.Stop) | 
					
						
							| 
									
										
										
										
											2023-03-08 13:57:41 +01:00
										 |  |  | 	tryUntil("stopping gtsmodel.Webfinger cache", 5, c.webfinger.Stop) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) Account() *result.Cache[*gtsmodel.Account] { | 
					
						
							|  |  |  | 	return c.account | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) Block() *result.Cache[*gtsmodel.Block] { | 
					
						
							|  |  |  | 	return c.block | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-14 09:55:36 +00:00
										 |  |  | func (c *gtsCaches) DomainBlock() *domain.BlockCache { | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 	return c.domainBlock | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) Emoji() *result.Cache[*gtsmodel.Emoji] { | 
					
						
							|  |  |  | 	return c.emoji | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) EmojiCategory() *result.Cache[*gtsmodel.EmojiCategory] { | 
					
						
							|  |  |  | 	return c.emojiCategory | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-03 23:02:23 +00:00
										 |  |  | func (c *gtsCaches) Media() *result.Cache[*gtsmodel.MediaAttachment] { | 
					
						
							|  |  |  | 	return c.media | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | func (c *gtsCaches) Mention() *result.Cache[*gtsmodel.Mention] { | 
					
						
							|  |  |  | 	return c.mention | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) Notification() *result.Cache[*gtsmodel.Notification] { | 
					
						
							|  |  |  | 	return c.notification | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-10 15:19:05 +01:00
										 |  |  | func (c *gtsCaches) Report() *result.Cache[*gtsmodel.Report] { | 
					
						
							|  |  |  | 	return c.report | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | func (c *gtsCaches) Status() *result.Cache[*gtsmodel.Status] { | 
					
						
							|  |  |  | 	return c.status | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) Tombstone() *result.Cache[*gtsmodel.Tombstone] { | 
					
						
							|  |  |  | 	return c.tombstone | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) User() *result.Cache[*gtsmodel.User] { | 
					
						
							|  |  |  | 	return c.user | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 13:57:41 +01:00
										 |  |  | func (c *gtsCaches) Webfinger() *ttl.Cache[string, string] { | 
					
						
							|  |  |  | 	return c.webfinger | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | func (c *gtsCaches) initAccount() { | 
					
						
							| 
									
										
										
										
											2022-12-16 22:36:52 +00:00
										 |  |  | 	c.account = result.New([]result.Lookup{ | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 		{Name: "ID"}, | 
					
						
							|  |  |  | 		{Name: "URI"}, | 
					
						
							|  |  |  | 		{Name: "URL"}, | 
					
						
							|  |  |  | 		{Name: "Username.Domain"}, | 
					
						
							|  |  |  | 		{Name: "PublicKeyURI"}, | 
					
						
							|  |  |  | 	}, func(a1 *gtsmodel.Account) *gtsmodel.Account { | 
					
						
							|  |  |  | 		a2 := new(gtsmodel.Account) | 
					
						
							|  |  |  | 		*a2 = *a1 | 
					
						
							|  |  |  | 		return a2 | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 	}, config.GetCacheGTSAccountMaxSize()) | 
					
						
							|  |  |  | 	c.account.SetTTL(config.GetCacheGTSAccountTTL(), true) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) initBlock() { | 
					
						
							| 
									
										
										
										
											2022-12-16 22:36:52 +00:00
										 |  |  | 	c.block = result.New([]result.Lookup{ | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 		{Name: "ID"}, | 
					
						
							|  |  |  | 		{Name: "AccountID.TargetAccountID"}, | 
					
						
							|  |  |  | 		{Name: "URI"}, | 
					
						
							|  |  |  | 	}, func(b1 *gtsmodel.Block) *gtsmodel.Block { | 
					
						
							|  |  |  | 		b2 := new(gtsmodel.Block) | 
					
						
							|  |  |  | 		*b2 = *b1 | 
					
						
							|  |  |  | 		return b2 | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 	}, config.GetCacheGTSBlockMaxSize()) | 
					
						
							|  |  |  | 	c.block.SetTTL(config.GetCacheGTSBlockTTL(), true) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) initDomainBlock() { | 
					
						
							| 
									
										
										
										
											2022-12-14 09:55:36 +00:00
										 |  |  | 	c.domainBlock = domain.New( | 
					
						
							|  |  |  | 		config.GetCacheGTSDomainBlockMaxSize(), | 
					
						
							|  |  |  | 		config.GetCacheGTSDomainBlockTTL(), | 
					
						
							|  |  |  | 	) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) initEmoji() { | 
					
						
							| 
									
										
										
										
											2022-12-16 22:36:52 +00:00
										 |  |  | 	c.emoji = result.New([]result.Lookup{ | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 		{Name: "ID"}, | 
					
						
							|  |  |  | 		{Name: "URI"}, | 
					
						
							|  |  |  | 		{Name: "Shortcode.Domain"}, | 
					
						
							|  |  |  | 		{Name: "ImageStaticURL"}, | 
					
						
							|  |  |  | 	}, func(e1 *gtsmodel.Emoji) *gtsmodel.Emoji { | 
					
						
							|  |  |  | 		e2 := new(gtsmodel.Emoji) | 
					
						
							|  |  |  | 		*e2 = *e1 | 
					
						
							|  |  |  | 		return e2 | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 	}, config.GetCacheGTSEmojiMaxSize()) | 
					
						
							|  |  |  | 	c.emoji.SetTTL(config.GetCacheGTSEmojiTTL(), true) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) initEmojiCategory() { | 
					
						
							| 
									
										
										
										
											2022-12-16 22:36:52 +00:00
										 |  |  | 	c.emojiCategory = result.New([]result.Lookup{ | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 		{Name: "ID"}, | 
					
						
							|  |  |  | 		{Name: "Name"}, | 
					
						
							|  |  |  | 	}, func(c1 *gtsmodel.EmojiCategory) *gtsmodel.EmojiCategory { | 
					
						
							|  |  |  | 		c2 := new(gtsmodel.EmojiCategory) | 
					
						
							|  |  |  | 		*c2 = *c1 | 
					
						
							|  |  |  | 		return c2 | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 	}, config.GetCacheGTSEmojiCategoryMaxSize()) | 
					
						
							|  |  |  | 	c.emojiCategory.SetTTL(config.GetCacheGTSEmojiCategoryTTL(), true) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-03 23:02:23 +00:00
										 |  |  | func (c *gtsCaches) initMedia() { | 
					
						
							|  |  |  | 	c.media = result.New([]result.Lookup{ | 
					
						
							|  |  |  | 		{Name: "ID"}, | 
					
						
							|  |  |  | 	}, func(m1 *gtsmodel.MediaAttachment) *gtsmodel.MediaAttachment { | 
					
						
							|  |  |  | 		m2 := new(gtsmodel.MediaAttachment) | 
					
						
							|  |  |  | 		*m2 = *m1 | 
					
						
							|  |  |  | 		return m2 | 
					
						
							|  |  |  | 	}, config.GetCacheGTSMediaMaxSize()) | 
					
						
							|  |  |  | 	c.media.SetTTL(config.GetCacheGTSMediaTTL(), true) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | func (c *gtsCaches) initMention() { | 
					
						
							| 
									
										
										
										
											2022-12-16 22:36:52 +00:00
										 |  |  | 	c.mention = result.New([]result.Lookup{ | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 		{Name: "ID"}, | 
					
						
							|  |  |  | 	}, func(m1 *gtsmodel.Mention) *gtsmodel.Mention { | 
					
						
							|  |  |  | 		m2 := new(gtsmodel.Mention) | 
					
						
							|  |  |  | 		*m2 = *m1 | 
					
						
							|  |  |  | 		return m2 | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 	}, config.GetCacheGTSMentionMaxSize()) | 
					
						
							|  |  |  | 	c.mention.SetTTL(config.GetCacheGTSMentionTTL(), true) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) initNotification() { | 
					
						
							| 
									
										
										
										
											2022-12-16 22:36:52 +00:00
										 |  |  | 	c.notification = result.New([]result.Lookup{ | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 		{Name: "ID"}, | 
					
						
							|  |  |  | 	}, func(n1 *gtsmodel.Notification) *gtsmodel.Notification { | 
					
						
							|  |  |  | 		n2 := new(gtsmodel.Notification) | 
					
						
							|  |  |  | 		*n2 = *n1 | 
					
						
							|  |  |  | 		return n2 | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 	}, config.GetCacheGTSNotificationMaxSize()) | 
					
						
							|  |  |  | 	c.notification.SetTTL(config.GetCacheGTSNotificationTTL(), true) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-10 15:19:05 +01:00
										 |  |  | func (c *gtsCaches) initReport() { | 
					
						
							|  |  |  | 	c.report = result.New([]result.Lookup{ | 
					
						
							|  |  |  | 		{Name: "ID"}, | 
					
						
							|  |  |  | 	}, func(r1 *gtsmodel.Report) *gtsmodel.Report { | 
					
						
							|  |  |  | 		r2 := new(gtsmodel.Report) | 
					
						
							|  |  |  | 		*r2 = *r1 | 
					
						
							|  |  |  | 		return r2 | 
					
						
							|  |  |  | 	}, config.GetCacheGTSReportMaxSize()) | 
					
						
							|  |  |  | 	c.report.SetTTL(config.GetCacheGTSReportTTL(), true) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | func (c *gtsCaches) initStatus() { | 
					
						
							| 
									
										
										
										
											2022-12-16 22:36:52 +00:00
										 |  |  | 	c.status = result.New([]result.Lookup{ | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 		{Name: "ID"}, | 
					
						
							|  |  |  | 		{Name: "URI"}, | 
					
						
							|  |  |  | 		{Name: "URL"}, | 
					
						
							|  |  |  | 	}, func(s1 *gtsmodel.Status) *gtsmodel.Status { | 
					
						
							|  |  |  | 		s2 := new(gtsmodel.Status) | 
					
						
							|  |  |  | 		*s2 = *s1 | 
					
						
							|  |  |  | 		return s2 | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 	}, config.GetCacheGTSStatusMaxSize()) | 
					
						
							|  |  |  | 	c.status.SetTTL(config.GetCacheGTSStatusTTL(), true) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // initTombstone will initialize the gtsmodel.Tombstone cache. | 
					
						
							|  |  |  | func (c *gtsCaches) initTombstone() { | 
					
						
							| 
									
										
										
										
											2022-12-16 22:36:52 +00:00
										 |  |  | 	c.tombstone = result.New([]result.Lookup{ | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 		{Name: "ID"}, | 
					
						
							|  |  |  | 		{Name: "URI"}, | 
					
						
							|  |  |  | 	}, func(t1 *gtsmodel.Tombstone) *gtsmodel.Tombstone { | 
					
						
							|  |  |  | 		t2 := new(gtsmodel.Tombstone) | 
					
						
							|  |  |  | 		*t2 = *t1 | 
					
						
							|  |  |  | 		return t2 | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 	}, config.GetCacheGTSTombstoneMaxSize()) | 
					
						
							|  |  |  | 	c.tombstone.SetTTL(config.GetCacheGTSTombstoneTTL(), true) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) initUser() { | 
					
						
							| 
									
										
										
										
											2022-12-16 22:36:52 +00:00
										 |  |  | 	c.user = result.New([]result.Lookup{ | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | 		{Name: "ID"}, | 
					
						
							|  |  |  | 		{Name: "AccountID"}, | 
					
						
							|  |  |  | 		{Name: "Email"}, | 
					
						
							|  |  |  | 		{Name: "ConfirmationToken"}, | 
					
						
							|  |  |  | 		{Name: "ExternalID"}, | 
					
						
							|  |  |  | 	}, func(u1 *gtsmodel.User) *gtsmodel.User { | 
					
						
							|  |  |  | 		u2 := new(gtsmodel.User) | 
					
						
							|  |  |  | 		*u2 = *u1 | 
					
						
							|  |  |  | 		return u2 | 
					
						
							| 
									
										
										
										
											2022-12-11 13:03:15 +00:00
										 |  |  | 	}, config.GetCacheGTSUserMaxSize()) | 
					
						
							|  |  |  | 	c.user.SetTTL(config.GetCacheGTSUserTTL(), true) | 
					
						
							| 
									
										
										
										
											2022-12-08 17:35:14 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-03-08 13:57:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (c *gtsCaches) initWebfinger() { | 
					
						
							|  |  |  | 	c.webfinger = ttl.New[string, string]( | 
					
						
							|  |  |  | 		0, | 
					
						
							|  |  |  | 		config.GetCacheGTSWebfingerMaxSize(), | 
					
						
							|  |  |  | 		config.GetCacheGTSWebfingerTTL()) | 
					
						
							|  |  |  | } |