Merged in feature/textextract (pull request #108)

Start adding Textract + UUID changes

* base

* startclient

* ts

* short

* tests
This commit is contained in:
Michael McGuinness
2025-03-20 11:06:41 +00:00
parent 1587da9d11
commit 53ea7d34e6
196 changed files with 25972 additions and 1456 deletions
+7 -4
View File
@@ -7,7 +7,6 @@ import (
"fmt"
"log/slog"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/document"
"queryorchestration/internal/serviceconfig/build"
@@ -88,7 +87,7 @@ func (s *Service) executeCleanTasks(ctx context.Context, params *CleanParams) (*
func (s *Service) clean(ctx context.Context, id uuid.UUID) error {
slog.Debug("cleaning document", "id", id.String())
docId := database.MustToDBUUID(id)
docId := id
doc, err := s.cfg.GetDBQueries().GetDocumentSummary(ctx, docId)
if err != nil {
@@ -121,7 +120,7 @@ func (s *Service) clean(ctx context.Context, id uuid.UUID) error {
}
func (s *Service) storeClean(ctx context.Context, id uuid.UUID, out *ExecuteCleanResponse) error {
docId := database.MustToDBUUID(id)
docId := id
version := build.GetVersionUnixTimestamp()
params := &repository.AddDocumentCleanParams{
@@ -174,7 +173,7 @@ func (s *Service) storeClean(ctx context.Context, id uuid.UUID, out *ExecuteClea
}
func (s *Service) isNewClean(lastEntry *repository.GetMostRecentDocumentCleanEntryRow, out *ExecuteCleanResponse) bool {
if lastEntry == nil || !lastEntry.ID.Valid {
if lastEntry == nil {
return true
}
@@ -186,6 +185,10 @@ func (s *Service) isNewClean(lastEntry *repository.GetMostRecentDocumentCleanEnt
return true
}
if out.location == nil || out.mimetype == nil || lastEntry.Bucket == nil || lastEntry.Key == nil {
return true
}
return !(out.location.Bucket == *lastEntry.Bucket &&
out.location.Key == *lastEntry.Key &&
*out.mimetype == ParseDBNullMimeType(lastEntry.Mimetype))
+14 -15
View File
@@ -6,7 +6,6 @@ import (
"strings"
"testing"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/document"
objectstoremock "queryorchestration/mocks/objectstore"
@@ -44,12 +43,12 @@ func TestClean(t *testing.T) {
Bucket: "bucket_name",
Key: "/i/am/here",
}
dbid := database.MustToDBUUID(doc.ID)
dbid := doc.ID
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(dbid).
WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
AddRow(dbid, database.MustToDBUUID(doc.ClientID), doc.Hash),
AddRow(dbid, doc.ClientID, doc.Hash),
)
pool.ExpectQuery("name: GetDocumentEntry :one").WithArgs(dbid).WillReturnRows(
pgxmock.NewRows([]string{"documentId", "bucket", "key"}).
@@ -65,7 +64,7 @@ func TestClean(t *testing.T) {
WillReturnRows(
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}),
)
cleanid := database.MustToDBUUID(uuid.New())
cleanid := uuid.New()
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &inloc.Bucket, &inloc.Key, dbmimetype, repository.NullCleanfailtype{}).
WillReturnRows(
pgxmock.NewRows([]string{"id"}).
@@ -186,7 +185,7 @@ func TestStoreClean(t *testing.T) {
location: &inloc,
mimetype: (*MimeType)(&mimeType),
}
dbid := database.MustToDBUUID(doc.ID)
dbid := doc.ID
dbmimetype := repository.NullCleanmimetype{
Valid: true,
@@ -197,7 +196,7 @@ func TestStoreClean(t *testing.T) {
WillReturnRows(
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}),
)
cleanid := database.MustToDBUUID(uuid.New())
cleanid := uuid.New()
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &inloc.Bucket, &inloc.Key, dbmimetype, repository.NullCleanfailtype{}).
WillReturnRows(
pgxmock.NewRows([]string{"id"}).
@@ -216,7 +215,7 @@ func TestStoreClean(t *testing.T) {
location: &inloc,
mimetype: (*MimeType)(&mimeType),
}
dbid := database.MustToDBUUID(doc.ID)
dbid := doc.ID
dbmimetype := repository.NullCleanmimetype{
Valid: true,
@@ -226,9 +225,9 @@ func TestStoreClean(t *testing.T) {
pool.ExpectQuery("name: GetMostRecentDocumentCleanEntry :one").WithArgs(dbid).
WillReturnRows(
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
AddRow(database.MustToDBUUID(uuid.New()), dbid, nil, nil, int64(1), nil, repository.CleanfailtypeInvalidRead),
AddRow(uuid.New(), dbid, nil, nil, int64(1), nil, repository.CleanfailtypeInvalidRead),
)
cleanid := database.MustToDBUUID(uuid.New())
cleanid := uuid.New()
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &inloc.Bucket, &inloc.Key, dbmimetype, repository.NullCleanfailtype{}).
WillReturnRows(
pgxmock.NewRows([]string{"id"}).
@@ -246,8 +245,8 @@ func TestStoreClean(t *testing.T) {
params := &ExecuteCleanResponse{
failReason: &reason,
}
dbid := database.MustToDBUUID(doc.ID)
cleanid := database.MustToDBUUID(uuid.New())
dbid := doc.ID
cleanid := uuid.New()
pool.ExpectBegin()
pool.ExpectQuery("name: GetMostRecentDocumentCleanEntry :one").WithArgs(dbid).
@@ -276,7 +275,7 @@ func TestIsNewClean(t *testing.T) {
})
t.Run("same fail", func(t *testing.T) {
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
ID: database.MustToDBUUID(uuid.New()),
ID: uuid.New(),
Fail: repository.NullCleanfailtype{
Valid: true,
Cleanfailtype: repository.CleanfailtypeInvalidMimetype,
@@ -290,7 +289,7 @@ func TestIsNewClean(t *testing.T) {
})
t.Run("different fail", func(t *testing.T) {
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
ID: database.MustToDBUUID(uuid.New()),
ID: uuid.New(),
Fail: repository.NullCleanfailtype{
Valid: true,
Cleanfailtype: repository.CleanfailtypeInvalidMimetype,
@@ -309,7 +308,7 @@ func TestIsNewClean(t *testing.T) {
}
mimeType := MimeTypePDF
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
ID: database.MustToDBUUID(uuid.New()),
ID: uuid.New(),
Bucket: &loc.Bucket,
Key: &loc.Key,
Mimetype: repository.NullCleanmimetype{
@@ -334,7 +333,7 @@ func TestIsNewClean(t *testing.T) {
}
mimeType := MimeTypePDF
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
ID: database.MustToDBUUID(uuid.New()),
ID: uuid.New(),
Bucket: &ogloc.Bucket,
Key: &ogloc.Key,
Mimetype: repository.NullCleanmimetype{
+1 -2
View File
@@ -4,14 +4,13 @@ import (
"context"
doctextrunner "queryorchestration/api/docTextRunner"
"queryorchestration/internal/database"
"queryorchestration/internal/serviceconfig/queue"
"github.com/google/uuid"
)
func (s *Service) Clean(ctx context.Context, id uuid.UUID) error {
isclean, err := s.cfg.GetDBQueries().HasDocumentCleanEntry(ctx, database.MustToDBUUID(id))
isclean, err := s.cfg.GetDBQueries().HasDocumentCleanEntry(ctx, id)
if err != nil {
return err
}
+3 -4
View File
@@ -7,7 +7,6 @@ import (
"strings"
"testing"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/document"
"queryorchestration/internal/serviceconfig"
@@ -58,7 +57,7 @@ func TestCreate(t *testing.T) {
Bucket: "bucket_name",
Key: "/i/am/here",
}
dbid := database.MustToDBUUID(doc.ID)
dbid := doc.ID
pool.ExpectQuery("name: HasDocumentCleanEntry :one").WithArgs(dbid).WillReturnRows(
pgxmock.NewRows([]string{"isclean"}).
@@ -67,7 +66,7 @@ func TestCreate(t *testing.T) {
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(dbid).
WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
AddRow(dbid, database.MustToDBUUID(doc.ClientID), doc.Hash),
AddRow(dbid, doc.ClientID, doc.Hash),
)
pool.ExpectQuery("name: GetDocumentEntry :one").WithArgs(dbid).WillReturnRows(
pgxmock.NewRows([]string{"documentId", "bucket", "key"}).
@@ -83,7 +82,7 @@ func TestCreate(t *testing.T) {
WillReturnRows(
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}),
)
cleanid := database.MustToDBUUID(uuid.New())
cleanid := uuid.New()
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &inloc.Bucket, &inloc.Key, dbmimetype, repository.NullCleanfailtype{}).
WillReturnRows(
pgxmock.NewRows([]string{"id"}).