diff --git a/evidence/lab5/integration-test.txt b/evidence/lab5/integration-test.txt index aab0441..7d293ee 100644 --- a/evidence/lab5/integration-test.txt +++ b/evidence/lab5/integration-test.txt @@ -1,2 +1,2 @@ -ok mtusi-messenger/internal/storage/postgres 8.934s -ok mtusi-messenger/internal/storage/redis 1.229s +ok mtusi-messenger/internal/storage/postgres 8.765s +ok mtusi-messenger/internal/storage/redis 1.264s diff --git a/evidence/lab5/lint.txt b/evidence/lab5/lint.txt index 5341a79..e42d0c9 100644 --- a/evidence/lab5/lint.txt +++ b/evidence/lab5/lint.txt @@ -3,18 +3,18 @@ level=info msg="golangci-lint has version 2.13.2 built with go1.27.1 from (unkno level=info msg="[config_reader] Config search paths: [./ /Users/vladislav/Projects/mtusi2026lab5 /Users/vladislav/Projects /Users/vladislav /Users /]" level=info msg="[config_reader] Used config file .golangci.yml" level=info msg="[config_reader] Module name \"mtusi-messenger\"" -level=info msg="[goenv] Read go env for 6.899ms: map[string]string{\"GOCACHE\":\"/Users/vladislav/Library/Caches/go-build\", \"GOROOT\":\"/opt/homebrew/Cellar/go/1.27.1/libexec\"}" +level=info msg="[goenv] Read go env for 5.669667ms: map[string]string{\"GOCACHE\":\"/Users/vladislav/Library/Caches/go-build\", \"GOROOT\":\"/opt/homebrew/Cellar/go/1.27.1/libexec\"}" level=info msg="[lintersdb] Active 50 linters: [asasalint bodyclose canonicalheader containedctx contextcheck copyloopvar depguard durationcheck errcheck errname errorlint exhaustive exptostd fatcontext forbidigo forcetypeassert gocheckcompilerdirectives gocritic gofumpt goimports gomoddirectives gosec govet ineffassign intrange makezero misspell musttag nilerr nilnil noctx nolintlint perfsprint prealloc reassign recvcheck revive rowserrcheck sloglint sqlclosecheck staticcheck testifylint thelper tparallel unconvert unparam unused usestdlibvars usetesting wastedassign]" level=info msg="[loader] Using build tags: [integration]" -level=info msg="[loader] Go packages loading at mode 8767 (files|name|compiled_files|deps|exports_file|imports|types_sizes) took 386.58525ms" -level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 10.82225ms" -level=info msg="[linters_context/goanalysis] analyzers took 9.441069744s with top 10 stages: goimports: 2.162295625s, revive: 1.635175292s, gosec: 746.543207ms, unparam: 497.231375ms, wastedassign: 307.470709ms, gocritic: 147.325123ms, buildir: 145.809195ms, gofumpt: 123.647625ms, buildssa: 118.610962ms, nilness: 115.823328ms" +level=info msg="[loader] Go packages loading at mode 8767 (types_sizes|compiled_files|deps|exports_file|files|imports|name) took 398.270958ms" +level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 8.419166ms" +level=info msg="[linters_context/goanalysis] analyzers took 17.795929123s with top 10 stages: revive: 2.679376249s, goimports: 2.060329333s, gosec: 959.427623ms, unparam: 664.839042ms, buildir: 377.707742ms, wastedassign: 367.190043ms, buildssa: 253.050133ms, gocritic: 223.117835ms, sloglint: 209.844082ms, gofumpt: 182.648499ms" level=info msg="[runner/exclusion_rules] Skipped 8 issues by rules: [Path: \"_test\\\\.go\", Linters: \"gosec, prealloc, forcetypeassert, unparam\"]" level=info msg="[runner] Issues before processing: 881, after processing: 0" -level=info msg="[runner] Processors filtering stat (in/out): cgo: 881/881, exclusion_paths: 881/881, generated_file_filter: 881/292, exclusion_rules: 292/6, path_absoluter: 881/881, invalid_issue: 881/881, filename_unadjuster: 881/881, path_relativity: 881/881, nolint_filter: 6/0" -level=info msg="[runner] processing took 4.266378ms with stages: generated_file_filter: 2.538917ms, nolint_filter: 1.042041ms, exclusion_rules: 367.959µs, path_relativity: 277.792µs, invalid_issue: 13.084µs, cgo: 11.75µs, path_absoluter: 6.125µs, sort_results: 3.792µs, filename_unadjuster: 2.709µs, max_same_issues: 625ns, exclusion_paths: 458ns, fixer: 376ns, path_shortener: 126ns, path_prettifier: 125ns, max_from_linter: 125ns, max_per_file_from_linter: 125ns, uniq_by_line: 84ns, diff: 83ns, severity-rules: 41ns, source_code: 41ns" -level=info msg="[runner] linters took 2.049702792s with stages: goanalysis_metalinter: 2.045391875s" +level=info msg="[runner] Processors filtering stat (in/out): path_relativity: 881/881, nolint_filter: 6/0, path_absoluter: 881/881, cgo: 881/881, invalid_issue: 881/881, exclusion_paths: 881/881, generated_file_filter: 881/292, filename_unadjuster: 881/881, exclusion_rules: 292/6" +level=info msg="[runner] processing took 3.036ms with stages: generated_file_filter: 1.950667ms, nolint_filter: 532.917µs, path_relativity: 274.626µs, exclusion_rules: 236.792µs, invalid_issue: 18.708µs, cgo: 11.417µs, path_absoluter: 5.083µs, filename_unadjuster: 3.417µs, sort_results: 666ns, max_same_issues: 459ns, fixer: 291ns, exclusion_paths: 251ns, path_prettifier: 166ns, path_shortener: 124ns, diff: 84ns, uniq_by_line: 83ns, max_from_linter: 83ns, max_per_file_from_linter: 83ns, severity-rules: 42ns, source_code: 41ns" +level=info msg="[runner] linters took 2.038491625s with stages: goanalysis_metalinter: 2.035411833s" 0 issues. level=info msg="File cache stats: 0 entries of total size 0B" -level=info msg="Memory: 26 samples, avg is 277.9MB, max is 547.6MB" -level=info msg="Execution took 2.454527125s" +level=info msg="Memory: 26 samples, avg is 296.0MB, max is 586.1MB" +level=info msg="Execution took 2.45183725s" diff --git a/evidence/lab5/unit-test.txt b/evidence/lab5/unit-test.txt index bb08778..aafc6b4 100644 --- a/evidence/lab5/unit-test.txt +++ b/evidence/lab5/unit-test.txt @@ -6,35 +6,35 @@ env -u APP_ENV -u SERVER_HOST -u SERVER_PORT -u SERVER_READ_HEADER_TIMEOUT -u SE ? mtusi-messenger/cmd/s3init [no test files] ? mtusi-messenger/cmd/worker [no test files] ? mtusi-messenger/internal/broker [no test files] -ok mtusi-messenger/internal/config 1.385s -ok mtusi-messenger/internal/domain 2.358s +ok mtusi-messenger/internal/config 1.386s +ok mtusi-messenger/internal/domain 1.658s ? mtusi-messenger/internal/failpoint [no test files] -ok mtusi-messenger/internal/health 2.187s -ok mtusi-messenger/internal/imagecheck 2.045s -ok mtusi-messenger/internal/imageproc 3.557s -ok mtusi-messenger/internal/logger 2.942s +ok mtusi-messenger/internal/health 2.083s +ok mtusi-messenger/internal/imagecheck 4.315s +ok mtusi-messenger/internal/imageproc 5.409s +ok mtusi-messenger/internal/logger 4.670s ? mtusi-messenger/internal/outbox [no test files] -ok mtusi-messenger/internal/platform/cache 2.970s +ok mtusi-messenger/internal/platform/cache 4.248s ? mtusi-messenger/internal/platform/cache/mocks [no test files] -ok mtusi-messenger/internal/platform/objectstore 3.292s -ok mtusi-messenger/internal/platform/password 4.017s -ok mtusi-messenger/internal/platform/token 2.535s -ok mtusi-messenger/internal/service/attachment 1.665s +ok mtusi-messenger/internal/platform/objectstore 3.614s +ok mtusi-messenger/internal/platform/password 6.512s +ok mtusi-messenger/internal/platform/token 5.267s +ok mtusi-messenger/internal/service/attachment 5.575s ? mtusi-messenger/internal/service/attachment/mocks [no test files] -ok mtusi-messenger/internal/service/chat 3.495s +ok mtusi-messenger/internal/service/chat 5.869s ? mtusi-messenger/internal/service/chat/mocks [no test files] -ok mtusi-messenger/internal/service/message 1.866s +ok mtusi-messenger/internal/service/message 3.241s ? mtusi-messenger/internal/service/message/mocks [no test files] -ok mtusi-messenger/internal/service/session 4.403s +ok mtusi-messenger/internal/service/session 2.799s ? mtusi-messenger/internal/service/session/mocks [no test files] -ok mtusi-messenger/internal/service/user 4.032s +ok mtusi-messenger/internal/service/user 3.064s ? mtusi-messenger/internal/service/user/mocks [no test files] -ok mtusi-messenger/internal/storage/postgres 4.123s +ok mtusi-messenger/internal/storage/postgres 6.169s ? mtusi-messenger/internal/storage/postgres/internal/sqlcgen [no test files] ? mtusi-messenger/internal/storage/postgres/migrations [no test files] ? mtusi-messenger/internal/storage/redis [no test files] ? mtusi-messenger/internal/storage/redis/mocks [no test files] -ok mtusi-messenger/internal/transport/rest 4.446s +ok mtusi-messenger/internal/transport/rest 6.517s ? mtusi-messenger/internal/transport/rest/internal/oas [no test files] ? mtusi-messenger/internal/transport/rest/mocks [no test files] ? mtusi-messenger/internal/worker [no test files] diff --git a/internal/storage/postgres/internal/sqlcgen/attachments.sql.go b/internal/storage/postgres/internal/sqlcgen/attachments.sql.go index 031943c..4fa3568 100644 --- a/internal/storage/postgres/internal/sqlcgen/attachments.sql.go +++ b/internal/storage/postgres/internal/sqlcgen/attachments.sql.go @@ -7,10 +7,8 @@ package sqlcgen import ( "context" - "time" "github.com/google/uuid" - "github.com/jackc/pgx/v5/pgtype" ) const attachToMessage = `-- name: AttachToMessage :exec @@ -29,273 +27,6 @@ func (q *Queries) AttachToMessage(ctx context.Context, arg AttachToMessageParams return err } -const createAttachment = `-- name: CreateAttachment :one -INSERT INTO attachments ( - id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256, status -) -VALUES ( - $1, - $2, - $3, - $4, - $5, - $6, - $7, - $8, - 'pending' -) -RETURNING id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256, - status, error_code, created_at, updated_at -` - -type CreateAttachmentParams struct { - ID uuid.UUID - ChatID uuid.UUID - OwnerID uuid.UUID - ObjectKey string - Filename string - ContentType string - SizeBytes int64 - Sha256 string -} - -type CreateAttachmentRow struct { - ID uuid.UUID - ChatID uuid.UUID - OwnerID uuid.UUID - ObjectKey string - Filename string - ContentType string - SizeBytes int64 - Sha256 string - Status string - ErrorCode pgtype.Text - CreatedAt time.Time - UpdatedAt time.Time -} - -func (q *Queries) CreateAttachment(ctx context.Context, arg CreateAttachmentParams) (CreateAttachmentRow, error) { - row := q.db.QueryRow(ctx, createAttachment, - arg.ID, - arg.ChatID, - arg.OwnerID, - arg.ObjectKey, - arg.Filename, - arg.ContentType, - arg.SizeBytes, - arg.Sha256, - ) - var i CreateAttachmentRow - err := row.Scan( - &i.ID, - &i.ChatID, - &i.OwnerID, - &i.ObjectKey, - &i.Filename, - &i.ContentType, - &i.SizeBytes, - &i.Sha256, - &i.Status, - &i.ErrorCode, - &i.CreatedAt, - &i.UpdatedAt, - ) - return i, err -} - -const deletePendingAttachment = `-- name: DeletePendingAttachment :exec -DELETE FROM attachments -WHERE id = $1 - AND status = 'pending' -` - -func (q *Queries) DeletePendingAttachment(ctx context.Context, id uuid.UUID) error { - _, err := q.db.Exec(ctx, deletePendingAttachment, id) - return err -} - -const getAttachmentForMember = `-- name: GetAttachmentForMember :one -SELECT a.id, a.chat_id, a.owner_id, a.object_key, a.filename, a.content_type, - a.size_bytes, a.sha256, a.status, a.error_code, a.created_at, a.updated_at -FROM attachments a -JOIN chat_members cm - ON cm.chat_id = a.chat_id - AND cm.user_id = $1 -WHERE a.id = $2 -` - -type GetAttachmentForMemberParams struct { - UserID uuid.UUID - ID uuid.UUID -} - -type GetAttachmentForMemberRow struct { - ID uuid.UUID - ChatID uuid.UUID - OwnerID uuid.UUID - ObjectKey string - Filename string - ContentType string - SizeBytes int64 - Sha256 string - Status string - ErrorCode pgtype.Text - CreatedAt time.Time - UpdatedAt time.Time -} - -func (q *Queries) GetAttachmentForMember(ctx context.Context, arg GetAttachmentForMemberParams) (GetAttachmentForMemberRow, error) { - row := q.db.QueryRow(ctx, getAttachmentForMember, arg.UserID, arg.ID) - var i GetAttachmentForMemberRow - err := row.Scan( - &i.ID, - &i.ChatID, - &i.OwnerID, - &i.ObjectKey, - &i.Filename, - &i.ContentType, - &i.SizeBytes, - &i.Sha256, - &i.Status, - &i.ErrorCode, - &i.CreatedAt, - &i.UpdatedAt, - ) - return i, err -} - -const getAttachmentForOwner = `-- name: GetAttachmentForOwner :one -SELECT a.id, a.chat_id, a.owner_id, a.object_key, a.filename, a.content_type, - a.size_bytes, a.sha256, a.status, a.error_code, a.created_at, a.updated_at -FROM attachments a -JOIN chat_members cm - ON cm.chat_id = a.chat_id - AND cm.user_id = a.owner_id -WHERE a.id = $1 - AND a.owner_id = $2 -` - -type GetAttachmentForOwnerParams struct { - ID uuid.UUID - OwnerID uuid.UUID -} - -type GetAttachmentForOwnerRow struct { - ID uuid.UUID - ChatID uuid.UUID - OwnerID uuid.UUID - ObjectKey string - Filename string - ContentType string - SizeBytes int64 - Sha256 string - Status string - ErrorCode pgtype.Text - CreatedAt time.Time - UpdatedAt time.Time -} - -func (q *Queries) GetAttachmentForOwner(ctx context.Context, arg GetAttachmentForOwnerParams) (GetAttachmentForOwnerRow, error) { - row := q.db.QueryRow(ctx, getAttachmentForOwner, arg.ID, arg.OwnerID) - var i GetAttachmentForOwnerRow - err := row.Scan( - &i.ID, - &i.ChatID, - &i.OwnerID, - &i.ObjectKey, - &i.Filename, - &i.ContentType, - &i.SizeBytes, - &i.Sha256, - &i.Status, - &i.ErrorCode, - &i.CreatedAt, - &i.UpdatedAt, - ) - return i, err -} - -const listAttachmentKeys = `-- name: ListAttachmentKeys :many -SELECT id, object_key, status, created_at -FROM attachments -ORDER BY id -LIMIT $2 OFFSET $1 -` - -type ListAttachmentKeysParams struct { - RowOffset int32 - RowLimit int32 -} - -type ListAttachmentKeysRow struct { - ID uuid.UUID - ObjectKey string - Status string - CreatedAt time.Time -} - -func (q *Queries) ListAttachmentKeys(ctx context.Context, arg ListAttachmentKeysParams) ([]ListAttachmentKeysRow, error) { - rows, err := q.db.Query(ctx, listAttachmentKeys, arg.RowOffset, arg.RowLimit) - if err != nil { - return nil, err - } - defer rows.Close() - items := []ListAttachmentKeysRow{} - for rows.Next() { - var i ListAttachmentKeysRow - if err := rows.Scan( - &i.ID, - &i.ObjectKey, - &i.Status, - &i.CreatedAt, - ); err != nil { - return nil, err - } - items = append(items, i) - } - if err := rows.Err(); err != nil { - return nil, err - } - return items, nil -} - -const listAttachmentStatesForChat = `-- name: ListAttachmentStatesForChat :many -SELECT id, status -FROM attachments -WHERE chat_id = $1 - AND id = ANY($2::uuid[]) -` - -type ListAttachmentStatesForChatParams struct { - ChatID uuid.UUID - Ids []uuid.UUID -} - -type ListAttachmentStatesForChatRow struct { - ID uuid.UUID - Status string -} - -func (q *Queries) ListAttachmentStatesForChat(ctx context.Context, arg ListAttachmentStatesForChatParams) ([]ListAttachmentStatesForChatRow, error) { - rows, err := q.db.Query(ctx, listAttachmentStatesForChat, arg.ChatID, arg.Ids) - if err != nil { - return nil, err - } - defer rows.Close() - items := []ListAttachmentStatesForChatRow{} - for rows.Next() { - var i ListAttachmentStatesForChatRow - if err := rows.Scan(&i.ID, &i.Status); err != nil { - return nil, err - } - items = append(items, i) - } - if err := rows.Err(); err != nil { - return nil, err - } - return items, nil -} - const listMessageAttachments = `-- name: ListMessageAttachments :many SELECT message_id, attachment_id FROM message_attachments @@ -327,117 +58,3 @@ func (q *Queries) ListMessageAttachments(ctx context.Context, messageIds []uuid. } return items, nil } - -const listStalePendingAttachments = `-- name: ListStalePendingAttachments :many -SELECT id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256, - status, error_code, created_at, updated_at -FROM attachments -WHERE status = 'pending' - AND created_at < $1 -ORDER BY created_at -LIMIT $2 -` - -type ListStalePendingAttachmentsParams struct { - CreatedBefore time.Time - RowLimit int32 -} - -type ListStalePendingAttachmentsRow struct { - ID uuid.UUID - ChatID uuid.UUID - OwnerID uuid.UUID - ObjectKey string - Filename string - ContentType string - SizeBytes int64 - Sha256 string - Status string - ErrorCode pgtype.Text - CreatedAt time.Time - UpdatedAt time.Time -} - -func (q *Queries) ListStalePendingAttachments(ctx context.Context, arg ListStalePendingAttachmentsParams) ([]ListStalePendingAttachmentsRow, error) { - rows, err := q.db.Query(ctx, listStalePendingAttachments, arg.CreatedBefore, arg.RowLimit) - if err != nil { - return nil, err - } - defer rows.Close() - items := []ListStalePendingAttachmentsRow{} - for rows.Next() { - var i ListStalePendingAttachmentsRow - if err := rows.Scan( - &i.ID, - &i.ChatID, - &i.OwnerID, - &i.ObjectKey, - &i.Filename, - &i.ContentType, - &i.SizeBytes, - &i.Sha256, - &i.Status, - &i.ErrorCode, - &i.CreatedAt, - &i.UpdatedAt, - ); err != nil { - return nil, err - } - items = append(items, i) - } - if err := rows.Err(); err != nil { - return nil, err - } - return items, nil -} - -const markAttachmentReady = `-- name: MarkAttachmentReady :one -UPDATE attachments -SET status = 'ready', - object_key = $1, - updated_at = now() -WHERE id = $2 - AND status = 'pending' -RETURNING id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256, - status, error_code, created_at, updated_at -` - -type MarkAttachmentReadyParams struct { - ObjectKey string - ID uuid.UUID -} - -type MarkAttachmentReadyRow struct { - ID uuid.UUID - ChatID uuid.UUID - OwnerID uuid.UUID - ObjectKey string - Filename string - ContentType string - SizeBytes int64 - Sha256 string - Status string - ErrorCode pgtype.Text - CreatedAt time.Time - UpdatedAt time.Time -} - -func (q *Queries) MarkAttachmentReady(ctx context.Context, arg MarkAttachmentReadyParams) (MarkAttachmentReadyRow, error) { - row := q.db.QueryRow(ctx, markAttachmentReady, arg.ObjectKey, arg.ID) - var i MarkAttachmentReadyRow - err := row.Scan( - &i.ID, - &i.ChatID, - &i.OwnerID, - &i.ObjectKey, - &i.Filename, - &i.ContentType, - &i.SizeBytes, - &i.Sha256, - &i.Status, - &i.ErrorCode, - &i.CreatedAt, - &i.UpdatedAt, - ) - return i, err -} diff --git a/internal/storage/postgres/queries/attachments.sql b/internal/storage/postgres/queries/attachments.sql index 830468a..930ffd0 100644 --- a/internal/storage/postgres/queries/attachments.sql +++ b/internal/storage/postgres/queries/attachments.sql @@ -1,56 +1,3 @@ --- name: CreateAttachment :one -INSERT INTO attachments ( - id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256, status -) -VALUES ( - sqlc.arg(id), - sqlc.arg(chat_id), - sqlc.arg(owner_id), - sqlc.arg(object_key), - sqlc.arg(filename), - sqlc.arg(content_type), - sqlc.arg(size_bytes), - sqlc.arg(sha256), - 'pending' -) -RETURNING id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256, - status, error_code, created_at, updated_at; - --- name: MarkAttachmentReady :one -UPDATE attachments -SET status = 'ready', - object_key = sqlc.arg(object_key), - updated_at = now() -WHERE id = sqlc.arg(id) - AND status = 'pending' -RETURNING id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256, - status, error_code, created_at, updated_at; - --- name: GetAttachmentForMember :one -SELECT a.id, a.chat_id, a.owner_id, a.object_key, a.filename, a.content_type, - a.size_bytes, a.sha256, a.status, a.error_code, a.created_at, a.updated_at -FROM attachments a -JOIN chat_members cm - ON cm.chat_id = a.chat_id - AND cm.user_id = sqlc.arg(user_id) -WHERE a.id = sqlc.arg(id); - --- name: GetAttachmentForOwner :one -SELECT a.id, a.chat_id, a.owner_id, a.object_key, a.filename, a.content_type, - a.size_bytes, a.sha256, a.status, a.error_code, a.created_at, a.updated_at -FROM attachments a -JOIN chat_members cm - ON cm.chat_id = a.chat_id - AND cm.user_id = a.owner_id -WHERE a.id = sqlc.arg(id) - AND a.owner_id = sqlc.arg(owner_id); - --- name: ListAttachmentStatesForChat :many -SELECT id, status -FROM attachments -WHERE chat_id = sqlc.arg(chat_id) - AND id = ANY(sqlc.arg(ids)::uuid[]); - -- name: AttachToMessage :exec INSERT INTO message_attachments (message_id, attachment_id, position) VALUES (sqlc.arg(message_id), sqlc.arg(attachment_id), sqlc.arg(position)); @@ -60,23 +7,3 @@ SELECT message_id, attachment_id FROM message_attachments WHERE message_id = ANY(sqlc.arg(message_ids)::uuid[]) ORDER BY message_id, position; - --- name: DeletePendingAttachment :exec -DELETE FROM attachments -WHERE id = sqlc.arg(id) - AND status = 'pending'; - --- name: ListStalePendingAttachments :many -SELECT id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256, - status, error_code, created_at, updated_at -FROM attachments -WHERE status = 'pending' - AND created_at < sqlc.arg(created_before) -ORDER BY created_at -LIMIT sqlc.arg(row_limit); - --- name: ListAttachmentKeys :many -SELECT id, object_key, status, created_at -FROM attachments -ORDER BY id -LIMIT sqlc.arg(row_limit) OFFSET sqlc.arg(row_offset);