Skip to content
New issue

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

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

Already on GitHub? # to your account

[Mobile-10] TTL for graphql client's cache #49

Merged
merged 12 commits into from
Apr 28, 2024
Merged

[Mobile-10] TTL for graphql client's cache #49

merged 12 commits into from
Apr 28, 2024

Conversation

simon-the-shark
Copy link
Member

I added TTL for the cache for our GraphQL client in our api_base module and adjusted its usage across the whole project to slightly different syntax.

New usage added to api_base's README as well.

ios/Podfile Outdated
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '12.0'
platform :ios, '14.0'

Choose a reason for hiding this comment

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

You have to consider if 14.0 is good idea

Copy link
Member Author

Choose a reason for hiding this comment

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

@marekkedzia I don't like it, but it's required by Google Maps SDK for iOS. It's been the case for a while, but somehow before the latest flutter update it didn't cause any problems, but now it doesn't build without this specified.

Copy link
Member Author

Choose a reason for hiding this comment

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

But it shouldn't be thaaaat bad. As far I've checked it only means dropping support for iPhone 6 and below

}

Future<bool> saveTimestamp<T>(QueryResult<T> response) async {
final stamp = response.timestamp.toUtc().toIso8601String();

Choose a reason for hiding this comment

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

create some util function that You will use every time You parse date in project. using .toIso....() might lead to some inaccuracy in future

@@ -0,0 +1,28 @@
import 'ttl_config.dart';

class Timestamp extends DateTime {

Choose a reason for hiding this comment

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

this is gr8

import 'ttl_config.dart';

class Timestamp extends DateTime {
Timestamp.nil(this.key) : super(0);

Choose a reason for hiding this comment

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

this class is very good aproach. use it to parse date in project too

abstract class TtlStrategy {
static const day = Duration(days: 1);
static const week = Duration(days: 7);
static const month = Duration(days: 28);

Choose a reason for hiding this comment

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

i think this might be missleading. its better to use thirtyDays var so its clear how many days it last. week and day is clear ofc but month is not

sciCirclesRepository: month,
tagsRepository: month,
mapBuildingsRepository: month,
departmentsRepository: threeMonths,

Choose a reason for hiding this comment

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

You have to ask yourself a question: "is GET departmentsRepository so heavy operation that I have to cache it for threeMonths?"

Future<FetchPolicy> build(TtlKey key) async {
/// returns FetchPolicy that loads from cache or fetch from network
final timestamp = await (await repository).getTimestamp();
if (await timestamp.isCacheUpToDate) {

Choose a reason for hiding this comment

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

check if this approach doesnt kill performence in some cases

buildingsData.valueOrNull?.where(_filterMethod),
); // or elsewhere a whole list, filtered by text field
return buildingsData?.where(
_filterMethod); // or elsewhere a whole list, filtered by text field

Choose a reason for hiding this comment

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

im not a fan of comments in code but i see that u use it very common. its ok its not a mistake but in some companies it might be taken as bad practice.

probably in "Pragmatic Programmer" book ive read quote "If You can comment it, You can fix it"

import '../../../utils/watch_locale.dart';
import '../../../utils/where_non_null_iterable.dart';
import 'getTags.graphql.dart';

part 'tags_repository.g.dart';


typedef Tag = Query$GetTags$tags; // just alias for shorter type name

Choose a reason for hiding this comment

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

this is very good practice, i use similar apporach very common

Choose a reason for hiding this comment

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

Typescript has some special package called ts-opaque, You can try find similar for flutter (or write some simple code yourself)

@marekkedzia
Copy link

just think about my comments but imo its ready to merge

@marekkedzia
Copy link

good work

@marekkedzia
Copy link

also now i have noticed that you have very clear git history. it looks very nice in repository

@simon-the-shark simon-the-shark merged commit 7e128bc into main Apr 28, 2024
@simon-the-shark simon-the-shark deleted the mobile-10 branch April 28, 2024 13:40
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mobile - 10] Implement TTL mechanism and strategy for api cache
2 participants