npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@qwe8652591/abap-recursive-query

v1.1.0

Published

ABAP Recursive Query Tool - SAP ABAP object extraction library

Downloads

110

Readme

AI Build Download - Redis 队列系统

基于 Redis 队列 + 生产者-消费者模式的 ABAP 递归查询下载系统。

🎯 核心特性

  • 高性能: 查询次数减少50%,速度提升3-10倍,过滤规则性能提升20倍
  • 可扩展: 支持水平扩展,100+并发消费者,优化的连接管理
  • 可靠性: 任务持久化,自动重试,断点续传
  • 零硬编码: 通用设计,适用于任何 SAP GUI 程序
  • 资源优化: Redis连接减少99%,内存占用大幅降低

📁 项目结构

src/
├── common/          # 通用组件(类型、配置、队列管理、工具函数)
├── producer/        # 生产者(并发递归查询,内存队列)
├── consumer/        # 消费者(文件下载,Redis队列)
└── cli/             # CLI 工具
    ├── query-object.ts    # 单体模式(推荐)
    ├── producer-cli.ts    # 只启动生产者
    └── consumer-cli.ts    # 只启动消费者

🚀 快速开始

1. 环境准备

# 安装 Redis
docker run -d --name redis -p 6379:6379 redis:latest

# 安装依赖
pnpm install

2. 配置环境变量

复制 env.example.env 并修改:

cp env.example .env

最少配置(.env):

# SAP 连接(必需)
SAP_URL=https://your-sap-system.com:8000
SAP_USERNAME=your_username
SAP_PASSWORD=your_password
SAP_CLIENT=100

# Redis 连接
REDIS_HOST=localhost
REDIS_PORT=6379

更多配置选项请参考 env.example 文件。

3. 使用

方式一:单体模式(推荐)

pnpm build
pnpm query -- PROGRAM SAPLMEGUI -d 3

# 带过滤规则
pnpm query -- CLASS CL_MY_CLASS -d 5 -e Z_OLD -x "*_TEST"

方式二:分离模式(高性能)

# 终端1:启动生产者
pnpm build
pnpm producer -- PROGRAM SAPLMEGUI -d 3
# 输出: Job ID: abc-123-def

# 终端2:启动消费者
pnpm consumer -- --job-id abc-123-def -c 50

# 或启动多个消费者进程实现水平扩展
pnpm consumer -- -c 50  # 进程1
pnpm consumer -- -c 50  # 进程2
pnpm consumer -- -c 50  # 进程3

🏗️ 架构说明

工作流程

用户请求
   ↓
Producer(生产者)
├─ 并发递归查询(10并发,内存队列)
├─ 提取依赖关系
├─ 缓存对象数据(gzip压缩)
└─ 生成任务 → Redis 队列
   ↓
Consumers(消费者集群)
├─ 从 Redis 拉取任务
├─ 读取缓存数据
├─ 下载源代码
└─ 处理附加数据(Include、结构体、屏幕等)

核心组件

  • common/RedisQueueManager: 队列和缓存管理
  • producer/RecursiveQueryProducer: 递归查询(内存队列)
  • consumer/FileDownloadConsumer: 文件下载(Redis队列)

📊 性能对比

| 指标 | 旧实现 | 新实现(10消费者) | 新实现(150消费者) | 提升 | |------|--------|------------------|-------------------|------| | 150对象耗时 | 22.5秒 | 7.5秒 | 2秒 | 最高10倍 | | 查询次数 | 300次 | 150次 | 150次 | 减少50% | | 并发能力 | 20 | 100+ | 100+ | 5倍+ |

📦 API 使用

import { 
    RedisQueueManager,
    RecursiveQueryProducer,
    FileDownloadConsumer 
} from '@qwe8652591/ai-build-download';

// 创建组件
const queueManager = new RedisQueueManager();
const producer = new RecursiveQueryProducer(queueManager);

// 提交查询
const jobId = await producer.submitQuery('PROGRAM', 'SAPLMEGUI', config);

// 启动消费者
const consumer = new FileDownloadConsumer(queueManager, './downloads', [jobId]);
await consumer.start([jobId]);

// 等待完成
await producer.waitForCompletion(jobId);

⚙️ 环境变量

| 变量 | 默认值 | 说明 | |------|--------|------| | REDIS_HOST | localhost | Redis 服务器地址 | | REDIS_PORT | 6379 | Redis 端口 | | PRODUCER_CONCURRENCY | 10 | 生产者并发查询数 | | CONCURRENT_CONSUMERS | 10 | 默认消费者数量 | | QUEUE_MAX_SIZE | 40 | 队列背压阈值 | | MAX_RETRIES | 3 | 最大重试次数 | | CACHE_EXPIRY | 1800 | 缓存过期时间(秒) | | ENABLE_COMPRESSION | true | 启用 gzip 压缩 |

🎮 CLI 命令

单体模式

# 基本查询
pnpm query -- PROGRAM SAPLMEGUI

# 带参数
pnpm query -- -t CLASS -n CL_MY_CLASS -d 5 -c 20

# 带过滤规则
pnpm query -- PROGRAM Z_PROG -e Z_OLD -x "*_TEST" -x "*_TMP"

# 完整帮助
pnpm query -- --help

分离模式

# 生产者
pnpm producer -- PROGRAM SAPLMEGUI -d 3

# 消费者(处理特定 Job)
pnpm consumer -- --job-id <job-id> -c 50

# 消费者(处理所有活跃 Job)
pnpm consumer -- -c 20

🐛 故障排查

Redis 连接失败

# 检查 Redis 是否运行
redis-cli ping
# 应该返回: PONG

查看队列状态

redis-cli

# 查看所有 Job
ZRANGE abap:job:index 0 -1

# 查看队列大小
GET abap:queue:size:<job-id>

📚 技术文档

详细的技术设计和实现说明请参考:

📄 License

MIT