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

[Marshaller] - Enhance data structure #167

Closed
LeadcodeDev opened this issue Jul 15, 2024 · 0 comments · Fixed by #168
Closed

[Marshaller] - Enhance data structure #167

LeadcodeDev opened this issue Jul 15, 2024 · 0 comments · Fixed by #168
Assignees

Comments

@LeadcodeDev
Copy link
Member

LeadcodeDev commented Jul 15, 2024

Context

The addition of category support within server channels has created a serialisation problem linked to non-existent channels within the cache.

Proposal

Cache structure

├── root
│  └── user-[user_id]
│  └── server-[server_id]
│  └── server-[server_id]/emoji-[emoji_id]
│  └── server-[server_id]/member-[emoji_id]
final class Marshaller {
  // Cache structure
  Map<String, dynamic> _cache = {};

  Future<void> putServer(Server server) async {
    final rawServer = serializers.servers.deserialize(server);
    _cache.put('server-${server.id}', rawServer);
    
    for (final role in server.roles.list) {
      final rawRole = await serializers.roles.deserialize(role)
      _cache.put('server-${server.id}/role-${role.id}', rawRole);
    }

    for (final emoji in emojis.list) {
      final rawEmoji = await serializers.emojis.deserialize(emoji)
      _cache.put('server-${server.id}/emoji-${emoji.id}', rawEmoji);
    }
  }

  Future<({ Server? instance, Map<String, dynamic>? struct })> getServer(String id) async {
    final cachedServer = await _cache.getOrFail('server-$id');
    
    return (
      instance: cachedServer != null 
        ? await serializers.servers.cacheSerializer(cachedServer) 
        : null,
      struct: cachedServer
    );
  }
}

Cached data structures

Channel

├── <channel>
│  └── id
│  └── name
│  └── Map<Snowflake, User> users

Server

├── Server
│  └── id
│  └── name
│  └── List<Snowflake> members
│  └── List<Snowflake> channels

Serializers

abstract interface class Serializer<T> {
  T remoteSerializer(Map<String, dynamic>);
  T cacheSerializer(Map<String, dynamic>);
  Map<String, dynamic> deserialize(T);
}
@LeadcodeDev LeadcodeDev self-assigned this Jul 15, 2024
@LeadcodeDev LeadcodeDev converted this from a draft issue Jul 15, 2024
@LeadcodeDev LeadcodeDev moved this from Backlog to Work In Progress in Roadmap Jul 17, 2024
@LeadcodeDev LeadcodeDev moved this from Work In Progress to Done in Roadmap Jul 21, 2024
@LeadcodeDev LeadcodeDev closed this as completed by moving to Done in Roadmap Jul 21, 2024
@LeadcodeDev LeadcodeDev moved this from Done to Code Review in Roadmap Jul 21, 2024
@LeadcodeDev LeadcodeDev linked a pull request Jul 22, 2024 that will close this issue
@LeadcodeDev LeadcodeDev moved this from Code Review to Done in Roadmap Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
1 participant