From 419099a0def49e2f63d73d8052a685ff4f9122ba Mon Sep 17 00:00:00 2001 From: SoXX Date: Wed, 3 Jul 2024 22:57:04 +0200 Subject: [PATCH] feat: upload Posts in batch (no tests) --- pkg/database/post.go | 4 ++++ pkg/database/postgres.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pkg/database/post.go b/pkg/database/post.go index fb0665a..c30e948 100644 --- a/pkg/database/post.go +++ b/pkg/database/post.go @@ -2,6 +2,7 @@ package database import ( "context" + "gorm.io/gorm" "git.dragse.it/anthrove/otter-space-sdk/v2/pkg/models" ) @@ -11,6 +12,9 @@ type Post interface { // CreatePost adds a new post to the database. CreatePost(ctx context.Context, anthrovePost *models.Post) error + // TODO: Everything + CreatePostInBatch(ctx context.Context, db *gorm.DB, anthrovePost []models.Post, batchSize int) error + // GetPostByAnthroveID retrieves a post by its Anthrove ID. GetPostByAnthroveID(ctx context.Context, anthrovePostID models.AnthrovePostID) (*models.Post, error) diff --git a/pkg/database/postgres.go b/pkg/database/postgres.go index 08750d6..8931973 100644 --- a/pkg/database/postgres.go +++ b/pkg/database/postgres.go @@ -92,6 +92,10 @@ func (p *postgresqlConnection) CreatePost(ctx context.Context, anthrovePost *mod return postgres.CreatePost(ctx, p.db, anthrovePost) } +func (p *postgresqlConnection) CreatePostInBatch(ctx context.Context, db *gorm.DB, anthrovePost []models.Post, batchSize int) error { + return postgres.CreatePostInBatch(ctx, p.db, anthrovePost, batchSize) +} + func (p *postgresqlConnection) CreatePostWithReferenceToTagAnd(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.Tag) error { return postgres.CreateTagAndReferenceToPost(ctx, p.db, anthrovePostID, anthroveTag) }