# Phase 3 Week 11: Database Partitioning & Scalability - PROGRESS

**Date:** 2026-02-07
**Status:** STARTED

---

## 📋 Objectives

1.  **Table Partitioning:** optimizes queries for 10M+ posts.
    *   Partition `wp_mpz_translations` by `element_type`.
    *   Partition `wp_mpz_workflow_history` (if exists) or similar log tables by date.
2.  **Read Replicas:**
    *   Implement `DatabasePool` for read/write splitting.
3.  **Query Optimization:**
    *   Audit and optimize slow queries.

## 🛠️ Tasks

### 1. Database Partitioning
- [x] Create `DatabasePartitioner` class.
- [x] Implement partitioning for `wp_mpz_translations`.
- [x] Implement partitioning for `wp_mpz_translation_jobs` (Workflow logs).
- [x] Add CLI command or Admin tool to apply partitioning (since it's a structural change) - *Implemented as Migration*

### 2. Read Replicas
- [x] Create `DatabasePool` class.
- [x] Implement connection pooling.
- [x] Implement `get_reader()` and `get_writer()` methods.
- [x] Integrate with `MPZAdapter` and other core classes.

### 3. Optimization
- [x] Audit queries in `MPZAdapter`.
- [x] Add necessary indexes. (Found indexes were mostly adequate, verified in audit)

---

## 📝 Implementation Notes

- **Partitioning:** MySQL partitioning requires the partition key to be part of the primary key. This might require schema changes.
- **DatabasePool:** Needs to be singleton and handle `wpdb` connections.

---
