Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostedTransactionCache: add a TTL to every transaction #3023

Closed
wants to merge 1 commit into from

Conversation

NachoSoto
Copy link
Contributor

This was suggested in #2914 as a way to prevent the cache from growing forever.

Other changes:

  • Added PostedTransactionCache.unpostedTransactions: this was added in TransactionPoster: avoid posting transactions multiple times #2914, so I put it here to prevent merge conflicts.
  • PostedTransactionCache now verifies that cache interaction doesn't happen in the main thread
  • Added debug log when saving transactions
  • Added debug log when pruning cache
  • Added ClockType tests

This was suggested in #2914 as a way to prevent the cache from growing forever.

### Other changes:
- Added `PostedTransactionCache.unpostedTransactions`: this was added in #2914, so I put it here to prevent merge conflicts.
- `PostedTransactionCache` now verifies that cache interaction doesn't happen in the main thread
- Added debug log when saving transactions
- Added debug log when pruning cache
- Added `ClockType` tests
@NachoSoto NachoSoto requested a review from a team August 16, 2023 17:05
Comment on lines +47 to +48
self.pruneOldTransactions(from: &transactions)
transactions[transaction.transactionIdentifier] = self.clock.now
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire modification is done in place so we don't end up with 2 dictionary copies in memory.

@@ -54,4 +56,105 @@ class PostedTransactionCacheTests: TestCase {
expect(self.cache.hasPostedTransaction(transaction2)) == true
}

func testHasPostedTransactionDoesNotTakeDateIntoAccount() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes hasPostedTransaction faster, we only prune when writing.

@NachoSoto
Copy link
Contributor Author

Closing this. As shown in #3020 this won't work with that 😢

@NachoSoto NachoSoto closed this Aug 16, 2023
NachoSoto added a commit that referenced this pull request Aug 17, 2023
This is extracted from #3023. That's closed but this is still useful.
@NachoSoto NachoSoto deleted the transaction-cache-ttl branch August 28, 2023 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant