最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

laravel - Is there a way to "Eager Load" entire models from (cached) files, so database not is asked and yet t

programmeradmin7浏览0评论

I work with Laravel 12 in a browser based game evironment with a lot of tables just containing basic/static data. Most of the time that is pretty convenient as you can do lots of game design changes and test stuff without changing code like big arrays.

On the other hand, there are lots of calls to those tables, all of which are pretty small, yet stress the database and in the end the bottleneck is I/O.

An example: There is

  • Models\Avatar
  • Models\AvatarItem (AvatarId, ItemId)
  • Models\Item
  • Models\ItemSocket (ItemId, SocketId)
  • Models\Socket

As you can imagine, there are Avatars having Items and those can have some Sockets. Now as you grow a userbase, all tables get more data, yet sockets stay the same. This table just holds basic data (e.g. 50 rows) of all known sockets there are. In my POV there is absolutely no need to select/join those over and over again, even if those selects are pretty fast, as MySQL holds them in memory and eager loading helps too. And there are quite a few of those basic data tables (not just Sockets).

I am looking for a sort of export of this Model export(Socket::all()) so I can later virtually import the cached data and Laravel does not see a difference. Maybe something like a VirtualModel that does return Socket::make($stuff) but 50 times and in a structure that works with relations the same as fetched/eager loaded.

Is there anything like this static "import" approach, to get rid of joins to tables without changes?

I tried caching too, yet find it hard make the Avatar::with([*100 links*]) work with cached results without losing the convenient coding style.

Cheers

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论