mongo

package
v0.4.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDuplicateEvent

func CheckDuplicateEvent(ctx context.Context, evt nostr.Event) (bool, error)

CheckDuplicateEvent checks if an event with the same ID already exists in the collection. Returns (isDuplicate, error) where error indicates a system error, not a duplicate.

func DisconnectDB

func DisconnectDB(client *mongo.Client)

DisconnectDB safely disconnects from MongoDB

func EnsureIndexes

func EnsureIndexes(client *mongo.Client, databaseName string) error

EnsureIndexes creates necessary indexes on all collections

func GetAllAuthorsFromRelay

func GetAllAuthorsFromRelay(cfg *cfgType.ServerConfig) []string

GetAllAuthorsFromRelay fetches all unique authors from MongoDB.

func GetClient

func GetClient() *mongo.Client

GetClient returns the MongoDB client

func GetCollection

func GetCollection(kind int) *mongo.Collection

func GetDatabaseName

func GetDatabaseName() string

GetDatabaseName returns the database name from config

func InitDB

func InitDB(cfg *cfgType.ServerConfig) (*mongo.Client, error)

InitDB establishes a connection to MongoDB with retry logic and graceful error handling

func InitDBSilent added in v0.4.11

func InitDBSilent(cfg *cfgType.ServerConfig) (*mongo.Client, error)

InitDBSilent attempts to connect to MongoDB without logging errors Useful for health checks where failures are expected

func InitDBWithRetry added in v0.4.11

func InitDBWithRetry(cfg *cfgType.ServerConfig, maxRetries int, baseDelay, timeout time.Duration) (*mongo.Client, error)

InitDBWithRetry establishes a MongoDB connection with configurable retry logic

func InitializeDatabase added in v0.4.11

func InitializeDatabase(cfg *cfgType.ServerConfig) (*mongo.Client, bool)

InitializeDatabase attempts to connect to MongoDB with graceful fallback

func IsClientHealthy added in v0.4.1

func IsClientHealthy(ctx context.Context) bool

IsClientHealthy checks if the MongoDB client is available and connected

func PurgeOldEventsOptimized

func PurgeOldEventsOptimized(cfg *cfgType.EventPurgeConfig)

PurgeOldEventsOptimized removes old events using cached whitelist data for bulk operations

func QueryEvents

func QueryEvents(filters []nostr.Filter, client *mongo.Client, databaseName string) ([]nostr.Event, error)

QueryEvents queries events from the MongoDB collection(s) based on filters

func ScheduleEventPurgingOptimized

func ScheduleEventPurgingOptimized(cfg *cfgType.ServerConfig)

ScheduleEventPurgingOptimized runs the optimized event purging at configurable intervals

func SetGlobalClient added in v0.4.11

func SetGlobalClient(newClient *mongo.Client, dbName string) error

SetGlobalClient safely sets the global MongoDB client (used for reconnection)

func StartMongoHealthMonitor added in v0.4.11

func StartMongoHealthMonitor(cfg *cfgType.ServerConfig)

StartMongoHealthMonitor runs background MongoDB health monitoring and reconnection

func StoreMongoEvent

func StoreMongoEvent(ctx context.Context, evt nostr.Event, client nostr.ClientInterface)

StoreMongoEvent processes and stores an event based on its kind

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL