Cache tag list, directories, and file status
This commit is contained in:
parent
24b869d0f6
commit
dd21635050
|
@ -20,10 +20,14 @@ class FileSystem : Operations
|
||||||
private string _source;
|
private string _source;
|
||||||
private TagProvider[] _tagProviders;
|
private TagProvider[] _tagProviders;
|
||||||
|
|
||||||
private string[][string] _tagCache;
|
|
||||||
|
|
||||||
private stat_t _sourceStat;
|
private stat_t _sourceStat;
|
||||||
|
|
||||||
|
private string[][string] _tagCache;
|
||||||
|
private stat_t[string] _statCache;
|
||||||
|
private string[][string] _dirCache;
|
||||||
|
|
||||||
|
private string[] _tagList;
|
||||||
|
|
||||||
this(string source, TagProvider[] tagProviders)
|
this(string source, TagProvider[] tagProviders)
|
||||||
{
|
{
|
||||||
_source = source;
|
_source = source;
|
||||||
|
@ -49,6 +53,13 @@ class FileSystem : Operations
|
||||||
_tagCache[file] ~= tagProvider.getTags(file);
|
_tagCache[file] ~= tagProvider.getTags(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_tagList = _tagCache.byValue()
|
||||||
|
.joiner
|
||||||
|
.array
|
||||||
|
.sort()
|
||||||
|
.uniq
|
||||||
|
.array;
|
||||||
}
|
}
|
||||||
|
|
||||||
override void getattr(const(char)[] path, ref stat_t stat)
|
override void getattr(const(char)[] path, ref stat_t stat)
|
||||||
|
@ -61,9 +72,17 @@ class FileSystem : Operations
|
||||||
stat.st_mode = _sourceStat.st_mode;
|
stat.st_mode = _sourceStat.st_mode;
|
||||||
}
|
}
|
||||||
else if(isFile(path.baseName))
|
else if(isFile(path.baseName))
|
||||||
|
{
|
||||||
|
if(path.baseName in _statCache)
|
||||||
|
{
|
||||||
|
stat = _statCache[path.baseName];
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
auto file = findFile(path.baseName);
|
auto file = findFile(path.baseName);
|
||||||
lstat(toStringz(file), &stat);
|
lstat(toStringz(file), &stat);
|
||||||
|
_statCache[path.baseName] = stat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -73,7 +92,7 @@ class FileSystem : Operations
|
||||||
|
|
||||||
bool isTag(const(char)[] name)
|
bool isTag(const(char)[] name)
|
||||||
{
|
{
|
||||||
return _tagCache.values.any!(a => a.canFind(name));
|
return _tagList.canFind(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFile(const(char)[] name)
|
bool isFile(const(char)[] name)
|
||||||
|
@ -95,12 +114,7 @@ class FileSystem : Operations
|
||||||
{
|
{
|
||||||
if(path == "/")
|
if(path == "/")
|
||||||
{
|
{
|
||||||
return _tagCache.byValue()
|
return _tagList;
|
||||||
.joiner
|
|
||||||
.array
|
|
||||||
.sort()
|
|
||||||
.uniq
|
|
||||||
.array;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -138,14 +152,19 @@ class FileSystem : Operations
|
||||||
|
|
||||||
override string[] readdir(const(char)[] path)
|
override string[] readdir(const(char)[] path)
|
||||||
{
|
{
|
||||||
|
if(path in _dirCache)
|
||||||
|
{
|
||||||
|
return _dirCache[path];
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Don't return tags if only one file (or files with exactly the same set of tags) files?
|
//TODO: Don't return tags if only one file (or files with exactly the same set of tags) files?
|
||||||
if (path == "/")
|
if (path == "/")
|
||||||
{
|
{
|
||||||
return getTags(path) ~ getFiles(path);
|
return _dirCache[path] = getTags(path) ~ getFiles(path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return getTags(path) ~ getFiles(path) ~ [".", ".."];
|
return _dirCache[path] = getTags(path) ~ getFiles(path) ~ [".", ".."];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue