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

Implement USD Redis Repository (cache) #58

Merged
merged 18 commits into from
Jul 22, 2024
Merged

Implement USD Redis Repository (cache) #58

merged 18 commits into from
Jul 22, 2024

Conversation

anxolin
Copy link
Contributor

@anxolin anxolin commented Jul 18, 2024

This PR implements a new repository that will allow the cache of the results from other USD Repositories.

This new repo can be configured with a Redis client instance and the proxied repository.
It will cache both values and their absence.

To review this PR you can see the tests. The are written using GIVEN/WHEN/THEN, so they should explain the specification of this new repo.

image

Bonus

In this PR in also did some other things maybe not super related to the goal of the PR

  • Added documentation to easily launch the tests for all projects, and for a particular project or file
  • Made Typescript more strict, this forced me to solve a lot of issues we had! A lot of the changes in this PR is fixing these errors (sorry, but this lack of strictness was causing issues and solved it now).

@anxolin anxolin changed the title Move datasources to its own dir Implement USD Redis Repository (cache) Jul 18, 2024
Copy link

socket-security bot commented Jul 18, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@types/[email protected] None 0 3.2 kB types
npm/@types/[email protected] None 0 2.09 MB types

🚮 Removed packages: npm/@types/[email protected]

View full report↗︎

@anxolin anxolin requested a review from alfetopito July 18, 2024 20:30
@anxolin anxolin marked this pull request as ready for review July 18, 2024 20:30
import fp from "fastify-plugin";
import { redis } from '../connections/redis';
import fp from 'fastify-plugin';
import { redisClient } from '@cowprotocol/repositories';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

redis client has been moved to the repositories layer

"strict": false,
"strictNullChecks": false,
"alwaysStrict": false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have energy now to solve twap project, so its the only one in non-strict mode

@@ -0,0 +1,274 @@
import { UsdRepositoryRedis } from './UsdRepositoryRedis';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test for the new repository

const NULL_VALUE = 'null';

@injectable()
export class UsdRepositoryRedis implements UsdRepository {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Main contribution of this PR, to create this redis repository

README.md Outdated
Comment on lines 71 to 74
nx run repositories:test --watch

# Run test on specific file
nx run repositories:test --watch --testFile=libs/repositories/src/UsdRepository/UsdRepositoryRedis.spec.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

Why default the test with --watch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean, I didn't add it as default, I just gave 3 representative examples. One runs all tests and finishes, another runs the test in watch mode for repository layer, last does the same for a specific file.

I consider this notes just hints for devs on somehing I found useful for myself

I will add some additional text in the comment to clarify

apps/api/src/app/routes/proxies/coingecko/index.ts Outdated Show resolved Hide resolved
libs/repositories/src/UsdRepository/UsdRepository.ts Outdated Show resolved Hide resolved
Base automatically changed from usd-orderbook-repo to main July 22, 2024 15:34
@anxolin anxolin requested a review from alfetopito July 22, 2024 16:30
@anxolin
Copy link
Contributor Author

anxolin commented Jul 22, 2024

Merging to consolidate, I will address any further comment as follow up

@anxolin anxolin enabled auto-merge (squash) July 22, 2024 16:41
@anxolin anxolin disabled auto-merge July 22, 2024 16:47
@anxolin anxolin merged commit ef4921c into main Jul 22, 2024
6 checks passed
@anxolin anxolin deleted the usd-repo-redis branch July 22, 2024 16:47
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.

2 participants