Skip to content

Commit

Permalink
Merge pull request #1752 from bakaphp/feat-light-cache
Browse files Browse the repository at this point in the history
refact: message cache
  • Loading branch information
kaioken committed Jul 31, 2024
2 parents 0e41934 + c0f448b commit eecffcd
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 17 deletions.
3 changes: 3 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
use Kanvas\Inventory\Regions\Observers\RegionObserver;
use Kanvas\Inventory\Status\Models\Status;
use Kanvas\Inventory\Status\Observers\StatusObserver;
use Kanvas\Inventory\Variants\Models\Variants;
use Kanvas\Inventory\Variants\Models\VariantsChannels;
use Kanvas\Inventory\Variants\Models\VariantsWarehouses;
use Kanvas\Inventory\Variants\Observers\VariantObserver;
use Kanvas\Inventory\Warehouses\Models\Warehouses;
use Kanvas\Inventory\Warehouses\Observers\VariantsWarehouseObserver;
use Kanvas\Inventory\Warehouses\Observers\WarehouseObserver;
Expand Down Expand Up @@ -82,6 +84,7 @@ public function boot()
VariantsWarehouses::observe(VariantsWarehouseObserver::class);
Channels::observe(ChannelObserver::class);
Products::observe(ProductsObserver::class);
Variants::observe(VariantObserver::class);
VariantsChannels::observe(VariantsChannelObserver::class);
UsersAssociatedApps::observe(UsersAssociatedAppsObserver::class);
UserCompanyApps::observe(UsersAssociatedCompaniesObserver::class);
Expand Down
22 changes: 12 additions & 10 deletions graphql/schemas/Guild/lead.graphql
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
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")
Expand All @@ -29,6 +29,7 @@ type Lead {
builder: "App\\GraphQL\\Social\\Queries\\Tags\\TagsQueries@getTagsBuilder"
)
files: [Filesystem!]!
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\Filesystem\\FilesystemQuery@getFileByGraphType"
Expand All @@ -39,6 +40,7 @@ type Lead {
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
2 changes: 2 additions & 0 deletions graphql/schemas/Inventory/product.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Product {
upc: String
status: Status
files: [Filesystem!]!
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\Filesystem\\FilesystemQuery@getFileByGraphType"
Expand All @@ -25,6 +26,7 @@ type Product {
productsTypes: ProductType @belongsTo
companies: Company! @belongsTo(relation: "company")
custom_fields: [CustomField!]!
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\CustomFields\\CustomFieldQuery@getAllByGraphType"
Expand Down
2 changes: 2 additions & 0 deletions graphql/schemas/Inventory/variant.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Variant {
serial_number: String
status: Status
files: [Filesystem]
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\Filesystem\\FilesystemQuery@getFileByGraphType"
Expand All @@ -36,6 +37,7 @@ type Variant {
resolver: "App\\GraphQL\\Inventory\\Types\\MetadataType@linkedStores"
)
custom_fields: [CustomField!]!
@cacheRedis
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\CustomFields\\CustomFieldQuery@getAllByGraphType"
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/Inventory/Products/Models/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Kanvas\Inventory\Products\Models;

use Awobaz\Compoships\Compoships;
use Baka\Traits\HasLightHouseCache;
use Baka\Traits\SlugTrait;
use Baka\Traits\UuidTrait;
use Baka\Users\Contracts\UserInterface;
Expand Down Expand Up @@ -53,6 +54,7 @@ class Products extends BaseModel
use LikableTrait;
use HasShopifyCustomField;
use HasTagsTrait;
use HasLightHouseCache;
use Searchable {
search as public traitSearch;
}
Expand All @@ -70,6 +72,11 @@ class Products extends BaseModel

protected $is_deleted;

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

/**
* categories.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Domains/Inventory/Products/Observers/ProductsObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ public function saved(Products $products): void
if ($products->wasChanged('products_types_id') && $products->productsTypes()->exists()) {
$products->productsTypes->setTotalProducts();
}

$products->clearLightHouseCache();
}

public function created(Products $products): void
{
if ($products->productsTypes()->exists()) {
$products->productsTypes->setTotalProducts();
}

$products->clearLightHouseCache();
}
}
8 changes: 8 additions & 0 deletions src/Domains/Inventory/Variants/Models/Variants.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Awobaz\Compoships\Compoships;
use Baka\Enums\StateEnums;
use Baka\Support\Str;
use Baka\Traits\HasLightHouseCache;
use Baka\Traits\SlugTrait;
use Baka\Traits\UuidTrait;
use Baka\Users\Contracts\UserInterface;
Expand Down Expand Up @@ -54,6 +55,7 @@ class Variants extends BaseModel
use UuidTrait;
use SocialInteractionsTrait;
use HasShopifyCustomField;
use HasLightHouseCache;
use Searchable {
search as public traitSearch;
}
Expand Down Expand Up @@ -83,9 +85,15 @@ class Variants extends BaseModel
'ean',
'apps_id',
];

protected $guarded = [];
protected static ?string $overWriteSearchIndex = null;

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

public static function searchableIndex(): string
{
return AppEnums::PRODUCT_VARIANTS_SEARCH_INDEX->getValue();
Expand Down
15 changes: 15 additions & 0 deletions src/Domains/Inventory/Variants/Observers/VariantObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Kanvas\Inventory\Variants\Observers;

use Kanvas\Inventory\Variants\Models\Variants;

class VariantObserver
{
public function saved(Variants $variant): void
{
$variant->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();
}
}
4 changes: 4 additions & 0 deletions src/Kanvas/Filesystem/Actions/AttachFilesystemAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public function execute(string $fieldName, ?int $id = null): FilesystemEntities
$this->entity->fireWorkflow(WorkflowEnum::ATTACH_FILE->value);
}

if (method_exists($this->entity, 'clearLightHouseCache')) {
$this->entity->clearLightHouseCache();
}

return $fileEntity;
}
}

0 comments on commit eecffcd

Please sign in to comment.