mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-18 23:38:35 +02:00
MISC: Improve several things relating to PID lookups (#1594)
findRunningScriptByPid needlessly took a "server" argument. This caused there to be a "getRunningScriptByPid" version that did *not*, and it was looping through all servers in order to function, which is needlessly inefficient. By removing the parameter and the needless inefficient helper method, the following changes: - Many Netscript functions such as isRunning() and getScript() become faster. - The terminal "tail" command now works by pid regardless of the current server. Note that "kill" already worked this way. I also improved the docs around "tail", since the pid argument wasn't in the help.
This commit is contained in:
@@ -10,7 +10,7 @@ import type { WorkerScript } from "./WorkerScript";
|
||||
|
||||
import React from "react";
|
||||
import { killWorkerScript } from "./killWorkerScript";
|
||||
import { GetAllServers, GetServer } from "../Server/AllServers";
|
||||
import { GetServer } from "../Server/AllServers";
|
||||
import { Player } from "@player";
|
||||
import { ScriptDeath } from "./ScriptDeath";
|
||||
import { formatExp, formatMoney, formatRam, formatThreads } from "../ui/formatNumber";
|
||||
@@ -649,17 +649,9 @@ export function getRunningScriptsByArgs(
|
||||
return findRunningScripts(path, scriptArgs, server);
|
||||
}
|
||||
|
||||
function getRunningScriptByPid(pid: number): RunningScript | null {
|
||||
for (const server of GetAllServers()) {
|
||||
const runningScript = findRunningScriptByPid(pid, server);
|
||||
if (runningScript) return runningScript;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function getRunningScript(ctx: NetscriptContext, ident: ScriptIdentifier): RunningScript | null {
|
||||
if (typeof ident === "number") {
|
||||
return getRunningScriptByPid(ident);
|
||||
return findRunningScriptByPid(ident);
|
||||
} else {
|
||||
const scripts = getRunningScriptsByArgs(ctx, ident.scriptname, ident.hostname, ident.args);
|
||||
if (scripts === null) return null;
|
||||
|
||||
Reference in New Issue
Block a user