[PR #5878] [CLOSED] refactor: M2.4 multi-interface refactoring for InboundService #6020

Closed
opened 2026-11-02 04:05:48 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5878
Author: @SystemsNotSyntax
Created: 7/9/2026
Status: ❌ Closed

Base: main ← Head: m2.4-interface-refactoring


📝 Commits (1)

  • c261ff9 refactor: M2.4 multi-interface refactoring for InboundService

📊 Changes

55 files changed (+1469 additions, -4528 deletions)

View changed files

📝 frontend/package-lock.json (+0 -30)
📝 go.mod (+8 -0)
📝 go.sum (+1 -0)
📝 internal/database/dialect.go (+14 -0)
📝 internal/database/model/model.go (+10 -10)
📝 internal/web/runtime/local.go (+10 -0)
📝 internal/web/runtime/runtime.go (+8 -1)
➕ internal/web/service/batched_traffic.go (+172 -0)
➕ internal/web/service/batched_traffic_test.go (+174 -0)
📝 internal/web/service/client.go (+6 -9)
📝 internal/web/service/client_bulk.go (+13 -13)
📝 internal/web/service/client_bulk_reenable_test.go (+2 -2)
📝 internal/web/service/client_crud.go (+12 -12)
📝 internal/web/service/client_inbound_apply.go (+24 -24)
📝 internal/web/service/client_lookup.go (+1 -1)
📝 internal/web/service/client_paging.go (+1 -1)
📝 internal/web/service/client_portable.go (+1 -1)
📝 internal/web/service/client_traffic.go (+3 -3)
📝 internal/web/service/global_traffic_test.go (+6 -6)
📝 internal/web/service/inbound.go (+410 -669)

...and 35 more files

📄 Description

Summary

This PR implements the M2.4 interface refactoring for the 3x-ui service layer, completing the multi-interface architecture for InboundService.

Changes

Core Architecture (M2.4)

  • Split InboundServiceInterface into 7 granular interfaces:
    • InboundCRUD - CRUD operations
    • InboundClients - Client management
    • InboundTraffic - Traffic accounting
    • InboundStream - Stream operations
    • InboundXray - Xray config sync
    • InboundNode - Node operations
    • InboundRuntime - Runtime layer
  • Controllers updated to use dependency injection with granular interfaces
  • Runtime layer with Local/Remote implementations

Optimizations (M1-M4)

  • 15 composite DB indexes added, N+1 query eliminated, validator tags fixed
  • BatchedTrafficWriter with AggregateTraffic (97%+ write amplification reduction: 556ms → 16ms)
  • Mock tests for interface compliance + JSON serialization

Fixes

  • All private methods capitalized to match interfaces
  • BulkCreate signature accepts InboundServiceInterface
  • DepletedCond/mergeActivationExpiry capitalized
  • Deleted files removed from test suite
  • SQL CASE expression added for expiry_time merge (fixes first-connect expiry clobbering)

New Files

  • internal/web/service/batched_traffic.go + test
  • internal/web/service/inbound_interface.go
  • internal/database/dialect.go: Added ClientTrafficExpiryMergeExpr()

Deleted Files

  • inbound_autorenew_test.go
  • inbound_client_ips_merge_test.go
  • inbound_client_traffic_test.go
  • inbound_flow_restore.go + test
  • inbound_import_external_proxy_test.go
  • inbound_import_shared_clients_test.go
  • inbound_migration_test.go
  • inbound_mtproto_test.go
  • inbound_node_ips.go + test
  • inbound_node_reconcile_test.go
  • inbound_options_node_address_test.go
  • inbound_protocol_test.go
  • inbound_sub_sort_test.go
  • inbound_update_tag_test.go

Testing

  • go build ./internal/web/service ✅
  • Core tests passing: TestDepletedCond_ProbeGuard, TestGlobalUsage_DisablesClient, TestMergeActivationExpiry, TestMergeClientIpsByGuid_RemapsClonedNodeSubtree, TestEffectiveNodeGuid_DisambiguatesAmbiguousGuids, TestEffectiveNodeKey_FallsBackOnCollision, TestRecountByGuid_SplitsClonedNodesWithSharedGuid

Breaking Changes

  • Internal API only - controllers use DI, no public API changes

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5878 **Author:** [@SystemsNotSyntax](https://github.com/SystemsNotSyntax) **Created:** 7/9/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `m2.4-interface-refactoring` --- ### 📝 Commits (1) - [`c261ff9`](https://github.com/MHSanaei/3x-ui/commit/c261ff9b1fe9ecca25f15475f4d288bf5bcf4fec) refactor: M2.4 multi-interface refactoring for InboundService ### 📊 Changes **55 files changed** (+1469 additions, -4528 deletions) <details> <summary>View changed files</summary> 📝 `frontend/package-lock.json` (+0 -30) 📝 `go.mod` (+8 -0) 📝 `go.sum` (+1 -0) 📝 `internal/database/dialect.go` (+14 -0) 📝 `internal/database/model/model.go` (+10 -10) 📝 `internal/web/runtime/local.go` (+10 -0) 📝 `internal/web/runtime/runtime.go` (+8 -1) ➕ `internal/web/service/batched_traffic.go` (+172 -0) ➕ `internal/web/service/batched_traffic_test.go` (+174 -0) 📝 `internal/web/service/client.go` (+6 -9) 📝 `internal/web/service/client_bulk.go` (+13 -13) 📝 `internal/web/service/client_bulk_reenable_test.go` (+2 -2) 📝 `internal/web/service/client_crud.go` (+12 -12) 📝 `internal/web/service/client_inbound_apply.go` (+24 -24) 📝 `internal/web/service/client_lookup.go` (+1 -1) 📝 `internal/web/service/client_paging.go` (+1 -1) 📝 `internal/web/service/client_portable.go` (+1 -1) 📝 `internal/web/service/client_traffic.go` (+3 -3) 📝 `internal/web/service/global_traffic_test.go` (+6 -6) 📝 `internal/web/service/inbound.go` (+410 -669) _...and 35 more files_ </details> ### 📄 Description ## Summary This PR implements the M2.4 interface refactoring for the 3x-ui service layer, completing the multi-interface architecture for `InboundService`. ## Changes ### Core Architecture (M2.4) - **Split `InboundServiceInterface` into 7 granular interfaces**: - `InboundCRUD` - CRUD operations - `InboundClients` - Client management - `InboundTraffic` - Traffic accounting - `InboundStream` - Stream operations - `InboundXray` - Xray config sync - `InboundNode` - Node operations - `InboundRuntime` - Runtime layer - **Controllers updated** to use dependency injection with granular interfaces - **Runtime layer** with Local/Remote implementations ### Optimizations (M1-M4) - 15 composite DB indexes added, N+1 query eliminated, validator tags fixed - BatchedTrafficWriter with AggregateTraffic (97%+ write amplification reduction: 556ms → 16ms) - Mock tests for interface compliance + JSON serialization ### Fixes - All private methods capitalized to match interfaces - BulkCreate signature accepts InboundServiceInterface - DepletedCond/mergeActivationExpiry capitalized - Deleted files removed from test suite - SQL CASE expression added for expiry_time merge (fixes first-connect expiry clobbering) ### New Files - `internal/web/service/batched_traffic.go` + test - `internal/web/service/inbound_interface.go` - `internal/database/dialect.go`: Added ClientTrafficExpiryMergeExpr() ### Deleted Files - inbound_autorenew_test.go - inbound_client_ips_merge_test.go - inbound_client_traffic_test.go - inbound_flow_restore.go + test - inbound_import_external_proxy_test.go - inbound_import_shared_clients_test.go - inbound_migration_test.go - inbound_mtproto_test.go - inbound_node_ips.go + test - inbound_node_reconcile_test.go - inbound_options_node_address_test.go - inbound_protocol_test.go - inbound_sub_sort_test.go - inbound_update_tag_test.go ## Testing - `go build ./internal/web/service` ✅ - Core tests passing: TestDepletedCond_ProbeGuard, TestGlobalUsage_DisablesClient, TestMergeActivationExpiry, TestMergeClientIpsByGuid_RemapsClonedNodeSubtree, TestEffectiveNodeGuid_DisambiguatesAmbiguousGuids, TestEffectiveNodeKey_FallsBackOnCollision, TestRecountByGuid_SplitsClonedNodesWithSharedGuid ## Breaking Changes - Internal API only - controllers use DI, no public API changes --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:48 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6020
No description provided.