Skip to content

Commit

Permalink
Loader optimization: Fix incorrect in-place sort of chunks by partiti…
Browse files Browse the repository at this point in the history
…on (#116)

* Fix incorrect in-place sort

* Update CHANGELOG
  • Loading branch information
lossyrob authored May 20, 2022
1 parent 78e7ad0 commit 3baae42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Fixed issue loader grouping an unordered iterable by partition, speeding up loads of items with mixed partitions [#116](https://github.com/stac-utils/pgstac/pull/116)

## [v0.6.3]

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion pypgstac/pypgstac/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ def load_items(
items = self.read_hydrated(file)

for chunk in chunked_iterable(items, chunksize):
list(chunk).sort(key=lambda x: x["partition"])
chunk = list(chunk)
chunk.sort(key=lambda x: x["partition"])
for k, g in itertools.groupby(chunk, lambda x: x["partition"]):
self.load_partition(self._partition_cache[k], g, insert_mode)

Expand Down

0 comments on commit 3baae42

Please sign in to comment.