Use git-grep instead of a db query
Use git-grep to look for the pattern, instead of searching the database.
This commit is contained in:
parent
80d5fc4ec2
commit
afe9eafba5
|
@ -27,8 +27,5 @@ class Grep(Command):
|
||||||
session = self.app.get_db_session()
|
session = self.app.get_db_session()
|
||||||
pm = project.ProjectManager(session)
|
pm = project.ProjectManager(session)
|
||||||
prj_filt = project_filter.ProjectFilter.from_parsed_args(parsed_args)
|
prj_filt = project_filter.ProjectFilter.from_parsed_args(parsed_args)
|
||||||
for r in pm.grep(parsed_args.pattern, prj_filt):
|
for l in pm.grep(parsed_args.pattern, prj_filt):
|
||||||
line_num, content, filename, project_name = r
|
print(l)
|
||||||
print('%s/%s:%s:%s' %
|
|
||||||
(project_name, filename, line_num, content.rstrip())
|
|
||||||
)
|
|
||||||
|
|
|
@ -205,12 +205,20 @@ class ProjectManager(object):
|
||||||
# function on the db session here instead of when we connect?
|
# function on the db session here instead of when we connect?
|
||||||
# We could pre-compile the regex and not pass it to each
|
# We could pre-compile the regex and not pass it to each
|
||||||
# invocation of the function.
|
# invocation of the function.
|
||||||
query = self.session.query(
|
query = self.session.query(Project)
|
||||||
Line.number, Line.content, File.name, Project.name,
|
|
||||||
).join(File, Project).filter(
|
|
||||||
Line.content.op('regexp')(pattern)
|
|
||||||
)
|
|
||||||
if prj_filter:
|
if prj_filter:
|
||||||
query = prj_filter.update_query(query)
|
query = prj_filter.update_query(query)
|
||||||
query = query.order_by(Project.name, File.name, Line.number)
|
query = query.order_by(Project.name)
|
||||||
return query.yield_per(20).all()
|
#return query.yield_per(20).all()
|
||||||
|
for project in query.all():
|
||||||
|
cmd = subprocess.Popen(
|
||||||
|
['git', 'grep', pattern],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
cwd=project.path,
|
||||||
|
env={'PAGER': ''},
|
||||||
|
)
|
||||||
|
out, err = cmd.communicate()
|
||||||
|
if not out:
|
||||||
|
continue
|
||||||
|
for line in out.decode('utf-8').splitlines():
|
||||||
|
yield project.name + line
|
||||||
|
|
Loading…
Reference in New Issue