Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reducing time spent opening/reading files when doing /replay list ... commands #293

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/bzfs/RecordReplay.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static bool replaceWorldDatabase(ReplayHeader *h);
static bool flagIsActive(FlagType *type);
static bool packFlagTypes(char *flags, u32 *flagsSize);

static bool getFileList(int playerIndex, std::vector<FileEntry>& entries);
static bool getFileList(int playerIndex, std::vector<FileEntry>& entries, std::string pattern);
static FILE *openFile(const char *filename, const char *mode);
static FILE *openWriteFile(int playerIndex, const char *filename);
static bool badFilename(const char *name);
Expand Down Expand Up @@ -718,7 +718,8 @@ bool Replay::loadFile(int playerIndex, const char *filename)
if (filename[0] == '#')
{
std::vector<FileEntry> entries;
if (!getFileList(playerIndex, entries))
// When selecting by index, we assume they searched without a query
if (!getFileList(playerIndex, entries, "*"))
{
sendMessage(ServerPlayer, playerIndex, "Could not get file index list");
return false;
Expand Down Expand Up @@ -862,7 +863,7 @@ static FILE *getRecordFile(const char *filename)
}


static bool getFileList(int playerIndex, std::vector<FileEntry>& entries)
static bool getFileList(int playerIndex, std::vector<FileEntry>& entries, std::string pattern)
{
entries.clear();
int entNum = 0;
Expand All @@ -883,6 +884,8 @@ static bool getFileList(int playerIndex, std::vector<FileEntry>& entries)
{
std::string name = RecordDir;
name += de->d_name;
if (!glob_match(name, pattern)) continue;
if (entNum > MaxListOutput) break;
FILE *file = getRecordFile(name.c_str());
if (file != NULL)
{
Expand Down Expand Up @@ -916,6 +919,8 @@ static bool getFileList(int playerIndex, std::vector<FileEntry>& entries)
{
std::string name = RecordDir;
name += findData.cFileName;
if (!glob_match(name, pattern)) continue;
if (entNum > MaxListOutput) break;
FILE *file = getRecordFile(name.c_str());
if (file != NULL)
{
Expand Down Expand Up @@ -1018,7 +1023,7 @@ bool Replay::sendFileList(int playerIndex, const char* options)
return false;

std::vector<FileEntry> entries;
if (!getFileList(playerIndex, entries))
if (!getFileList(playerIndex, entries, pattern))
return false;

char buffer[MessageLen];
Expand All @@ -1034,19 +1039,16 @@ bool Replay::sendFileList(int playerIndex, const char* options)
for (unsigned int i = 0; i < entries.size(); i++)
{
const FileEntry& entry = entries[i];
if (glob_match(pattern, entry.file))
entriesSent++;
snprintf(buffer, MessageLen, "#%02i: %-30s [%9.1f seconds]",
entry.entryNum + 1, entry.file.c_str(), entry.time);
sendMessage(ServerPlayer, playerIndex, buffer);
if (entriesSent >= MaxListOutput)
{
entriesSent++;
snprintf(buffer, MessageLen, "#%02i: %-30s [%9.1f seconds]",
entry.entryNum + 1, entry.file.c_str(), entry.time);
snprintf(buffer, MessageLen, "Not listing more then %i entries, "
"try using pattern matching.", MaxListOutput);
sendMessage(ServerPlayer, playerIndex, buffer);
if (entriesSent >= MaxListOutput)
{
snprintf(buffer, MessageLen, "Not listing more then %i entries, "
"try using pattern matching.", MaxListOutput);
sendMessage(ServerPlayer, playerIndex, buffer);
break;
}
break;
}
}

Expand Down