Skip to content

Commit

Permalink
refact: message cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken committed Jul 31, 2024
1 parent 6539c7c commit d74615f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 17 deletions.
24 changes: 14 additions & 10 deletions graphql/schemas/Guild/lead.graphql
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
type Lead {
id: ID!
uuid: String!
company: Company! @belongsTo
branch: CompanyBranch! @belongsTo
company: Company! @belongsTo @cacheRedis
branch: CompanyBranch! @belongsTo @cacheRedis
title: String!
people: People
user: User @belongsTo
owner: User @belongsTo
organization: Organization @belongsTo
receiver: LeadReceiver @belongsTo
status: LeadStatus @belongsTo
type: LeadType @belongsTo
source: LeadSource @belongsTo
user: User @belongsTo @cacheRedis
owner: User @belongsTo @cacheRedis
organization: Organization @belongsTo @cacheRedis
receiver: LeadReceiver @belongsTo @cacheRedis
status: LeadStatus @belongsTo @cacheRedis
type: LeadType @belongsTo @cacheRedis
source: LeadSource @belongsTo @cacheRedis
firstname: String
lastname: String
email: String
phone: String
description: String
reason_lost: String
pipeline: LeadPipeline @belongsTo
pipeline: LeadPipeline @belongsTo @cacheRedis
stage: LeadPipelineStage @belongsTo(relation: "stage")
participants: [LeadsParticipants!]! @hasMany
channels: [SocialChannel]! @hasMany(relation: "socialChannels")
systemModule: SystemModule
tags: [Tag!]
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Social\\Queries\\Tags\\TagsQueries@getTagsBuilder"
)
files: [Filesystem!]!
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\Filesystem\\FilesystemQuery@getFileByGraphType"
)
followers: [User!]!
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Social\\Builders\\Follows\\FollowBuilder@getEntityFollowers"
)
custom_fields: [CustomField!]!
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\CustomFields\\CustomFieldQuery@getAllByGraphType"
Expand Down
6 changes: 4 additions & 2 deletions graphql/schemas/Guild/people.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ type People {
organizations: [Organization!] @belongsToMany
contacts: [Contact!]! @hasMany
address: [Address!]! @hasMany

employment_history: [PeopleEmploymentHistory!]
@hasMany(relation: "employmentHistory")
files: [Filesystem!]!
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\Filesystem\\FilesystemQuery@getFileByGraphType"
)
custom_fields: [CustomField!]! @cacheRedis
custom_fields: [CustomField!]!
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\CustomFields\\CustomFieldQuery@getAllByGraphType"
Expand All @@ -31,6 +32,7 @@ type People {
builder: "App\\GraphQL\\Social\\Builders\\Interactions\\EntityInteractionsBuilder@getAll"
)
tags: [Tag!]
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Social\\Queries\\Tags\\TagsQueries@getTagsBuilder"
Expand Down
15 changes: 10 additions & 5 deletions graphql/schemas/Social/message.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ type Message {
total_liked: Int
total_saved: Int
total_shared: Int
parent: Message
user: User!
parent: Message @cacheRedis
user: User! @cacheRedis
children: [Message!] @hasMany(type: PAGINATOR)
messageType: MessageType!
appModuleMessage: AppModuleMessage
messageType: MessageType! @cacheRedis
appModuleMessage: AppModuleMessage @cacheRedis
myInteraction: myInteraction @method(name: "getMyInteraction")
comments: [MessageComments!]! @hasMany(type: PAGINATOR)
additional_field: Mixed
custom_fields: [CustomField!]!
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\CustomFields\\CustomFieldQuery@getAllByGraphType"
)
tags: [Tag!]
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Social\\Queries\\Tags\\TagsQueries@getTagsBuilder"
Expand Down Expand Up @@ -143,7 +145,10 @@ extend type Query @guard {
]
)
hasUser: _
@whereHasConditions(relation: "user", columns: ["id", "displayname"])
@whereHasConditions(
relation: "user"
columns: ["id", "displayname"]
)
hasAppModuleMessage: _
@whereHasConditions(columns: ["entity_id", "system_modules"])
orderBy: _ @orderBy(columns: ["created_at", "updated_at", "id"])
Expand Down
7 changes: 7 additions & 0 deletions src/Domains/Guild/Leads/Models/Lead.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Kanvas\Guild\Leads\Models;

use Baka\Support\Str;
use Baka\Traits\HasLightHouseCache;
use Baka\Traits\UuidTrait;
use Baka\Users\Contracts\UserInterface;
use Illuminate\Database\Eloquent\Builder;
Expand Down Expand Up @@ -65,6 +66,7 @@ class Lead extends BaseModel
use HasTagsTrait;
use FollowersTrait;
use CanUseWorkflow;
use HasLightHouseCache;

protected $table = 'leads';
protected $guarded = [];
Expand All @@ -74,6 +76,11 @@ public function people(): BelongsTo
return $this->belongsTo(People::class, 'people_id', 'id');
}

public function getGraphTypeName(): string
{
return 'Lead';
}

public function participants(): HasManyThrough
{
return $this->hasManyThrough(
Expand Down
3 changes: 3 additions & 0 deletions src/Domains/Guild/Leads/Observers/LeadObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ public function created(Lead $lead): void
)
)->execute();
}

$lead->clearLightHouseCache();
}

public function updated(Lead $lead): void
{
$lead->fireWorkflow(WorkflowEnum::UPDATED->value);
$lead->clearLightHouseCache();
}
}
7 changes: 7 additions & 0 deletions src/Domains/Social/Messages/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Kanvas\Social\Messages\Models;

use Baka\Casts\Json;
use Baka\Traits\HasLightHouseCache;
use Baka\Traits\SoftDeletesTrait;
use Baka\Traits\UuidTrait;
use Dyrynda\Database\Support\CascadeSoftDeletes;
Expand Down Expand Up @@ -57,6 +58,7 @@ class Message extends BaseModel
use HasPermissions;
use AsTree;
use CanUseWorkflow;
use HasLightHouseCache;

protected $table = 'messages';

Expand All @@ -68,6 +70,11 @@ class Message extends BaseModel
'message' => Json::class,
];

public function getGraphTypeName(): string
{
return 'Message';
}

protected $cascadeDeletes = ['comments'];

public const DELETED_AT = 'is_deleted';
Expand Down
2 changes: 2 additions & 0 deletions src/Domains/Social/Messages/Observers/MessageObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class MessageObserver
public function created(Message $message): void
{
$message->fireWorkflow(WorkflowEnum::CREATED->value, true, ['app' => $message->app]);
$message->clearLightHouseCache();
}

public function updated(Message $message): void
{
$message->fireWorkflow(WorkflowEnum::UPDATED->value, true, ['app' => $message->app]);
$message->clearLightHouseCache();
}
}

0 comments on commit d74615f

Please sign in to comment.