Skip to content

Commit

Permalink
fix: add new indexes & rework distinct (#449)
Browse files Browse the repository at this point in the history
fix: Improve Indexes & Transactions query
  • Loading branch information
flemzord committed Jul 4, 2023
1 parent 0b4ed01 commit 529ca39
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
19 changes: 8 additions & 11 deletions .goreleaser-darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ archives:
format_overrides:
- goos: windows
format: zip
name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"
replacements:
amd64: 64bit
386: 32bit
arm: ARM
arm64: ARM64
darwin: macOS
linux: Linux
windows: Windows

name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
checksum:
name_template: 'checksums-darwin.txt'
Expand All @@ -51,7 +48,7 @@ snapshot:
name_template: "{{ .Tag }}"

brews:
- tap:
- repository:
owner: formancehq
name: homebrew-tap
name: numary
Expand Down
16 changes: 7 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,13 @@ archives:
format_overrides:
- goos: windows
format: zip
name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"
replacements:
amd64: 64bit
386: 32bit
arm: ARM
arm64: ARM64
darwin: macOS
linux: Linux
windows: Windows
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
checksum:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--statement
CREATE INDEX IF NOT EXISTS postings_array_length_src ON "VAR_LEDGER_NAME".postings (jsonb_array_length(source));
--statement
CREATE INDEX IF NOT EXISTS postings_array_length_dst ON "VAR_LEDGER_NAME".postings (jsonb_array_length(destination));
--statement
CREATE INDEX IF NOT EXISTS accounts_array_length ON "VAR_LEDGER_NAME".accounts (jsonb_array_length(address_json));
--statement
CREATE INDEX IF NOT EXISTS volumes_array_length ON "VAR_LEDGER_NAME".volumes (jsonb_array_length(account_json));
8 changes: 6 additions & 2 deletions pkg/storage/sqlstorage/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ func (s *Store) buildTransactionsQuery(flavor Flavor, p ledger.TransactionsQuery
metadata = p.Filters.Metadata
)

sb.Select("id", "timestamp", "reference", "metadata", "postings", "pre_commit_volumes", "post_commit_volumes").
Distinct()
if flavor == SQLite {
sb.Select("id", "timestamp", "reference", "metadata", "postings", "pre_commit_volumes", "post_commit_volumes").
Distinct()
} else {
sb.Select("distinct on (id) id", "timestamp", "reference", "metadata", "postings", "pre_commit_volumes", "post_commit_volumes")
}
sb.From(s.schema.Table("transactions"))
if (source != "" || destination != "" || account != "") && flavor == PostgreSQL {
// new wildcard handling
Expand Down

0 comments on commit 529ca39

Please sign in to comment.