Skip to content

Commit

Permalink
Deduplicate files before and during templating (#3629)
Browse files Browse the repository at this point in the history
* Deduplicate in linter

* Deduplicate in templater

* Linting

* add more logging

* linting

* coverage

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
  • Loading branch information
alanmcruickshank and barrywhart committed Jul 23, 2022
1 parent 011e195 commit 8e4f29e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Expand Up @@ -307,6 +307,12 @@ def sequence_files(
for fname in fnames:
if fname not in already_yielded:
yield fname
# Dedupe here so we don't yield twice
already_yielded.add(fname)
else:
templater_logger.debug(
"- Skipping yield of previously sequenced file: %r", fname
)

@large_file_check
def process(self, *, fname, in_str=None, config=None, formatter=None):
Expand Down Expand Up @@ -450,6 +456,9 @@ def make_template(in_str):
return old_from_string(*args, **kwargs)

node = self._find_node(fname, config)
templater_logger.debug(
"_find_node for path %r returned object of type %s.", fname, type(node)
)

save_ephemeral_nodes = dict(
(k, v)
Expand Down
16 changes: 13 additions & 3 deletions src/sqlfluff/core/linter/linter.py
Expand Up @@ -1004,7 +1004,8 @@ def paths_from_path(
return sorted(buffer)

# Check the buffer for ignore items and normalise the rest.
filtered_buffer = []
# It's a set, so we can do natural deduplication.
filtered_buffer = set()

for fpath in buffer:
abs_fpath = os.path.abspath(fpath)
Expand All @@ -1031,9 +1032,18 @@ def paths_from_path(
)
break
else:
filtered_buffer.append(os.path.normpath(fpath))
npath = os.path.normpath(fpath)
# For debugging, log if we already have the file.
if npath in filtered_buffer:
linter_logger.debug( # pragma: no cover
"Developer Warning: Path crawler attempted to "
"requeue the same file twice. %s is already in "
"filtered buffer.",
npath,
)
filtered_buffer.add(npath)

# Return
# Return a sorted list
return sorted(filtered_buffer)

def lint_string_wrapped(
Expand Down

0 comments on commit 8e4f29e

Please sign in to comment.