sharedmemory-model

Enforce SharedMemoryModel imports for Django models to prevent N+1 queries.

4|1|Updated Feb 4, 2024
One-click install
npx skills add https://github.com/Arx-Game/arxii --skill sharedmemory-model
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sharedmemory-model
Source: https://github.com/Arx-Game/arxii/tree/main/tools/skills/sharedmemory-model
Command: npx skills add https://github.com/Arx-Game/arxii --skill sharedmemory-model

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

All concrete Django models in this repo should use Evennia's SharedMemoryModel, an identity map that caches FK walks and persists a Python object after the first load. This skill encodes usage rules and the identity-map caching discipline to prevent rebuilding complex caching or query-batching infrastructure.

Core Features & Use Cases

  • Enforces universal use of SharedMemoryModel for all concrete Django models.
  • Ensures correct import path: from evennia.utils.idmapper.models import SharedMemoryModel.
  • Prevents unsafe imports that trigger Django setup during import, and guides when to use SharedMemoryModel for caching-heavy or read-mostly data.
  • Use Case: optimize lookups on high-traffic models by avoiding repeated database hits through identity-mapped instances.

Quick Start

Migrate all Django models to SharedMemoryModel and start using its identity-map caching.

Frequently Asked Questions about sharedmemory-model

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent N+1 queries and cache-miss penalties on Django foreign key walks?

To prevent N+1 queries in Django, use SharedMemoryModel as the base class for all concrete models. It implements an identity map that caches foreign key walks and persists Python objects after their initial database load, avoiding redundant query execution.

What is the correct import path for SharedMemoryModel to avoid triggering Django setup during import?

The correct import path for SharedMemoryModel is `from evennia.utils.idmapper.models import SharedMemoryModel`. You must avoid importing from `evennia.utils.models` to prevent unsafe imports that prematurely trigger Django setup during module loading.

When do I need an identity map for caching read-mostly Django models?

You need an identity map for caching read-mostly Django models when optimizing lookups on high-traffic data. It prevents rebuilding complex caching infrastructure by ensuring repeated accesses retrieve the persisted Python object instead of executing new database queries.

How to migrate all concrete Django models to use SharedMemoryModel?

To migrate all concrete Django models to SharedMemoryModel, update the base class of every concrete model definition to inherit from `evennia.utils.idmapper.models.SharedMemoryModel`. This enforces identity-map caching discipline universally across the repository.

Can I use standard Django model classes instead of SharedMemoryModel for high-traffic lookups?

Using standard Django model classes instead of SharedMemoryModel for high-traffic lookups forfeits identity-map caching benefits. All concrete models in the repository should use SharedMemoryModel to prevent N+1 queries and avoid rebuilding custom query-batching infrastructure.