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

implement caching #51

Merged
merged 1 commit into from
Jan 4, 2024
Merged
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
18 changes: 15 additions & 3 deletions getFunctionData.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,28 @@ def get_function_data(repo_path='../inputData/testRepo'):
merge_commits = [commit for commit in repo.iter_commits('main') if commit.parents and len(commit.parents) > 1]
merge_commits.reverse()

ast_cache = {}

def get_ast_from_js(file_content):
# Generate a hash of the file content
content_hash = hash(file_content)

# Check if the AST is already in the cache
if content_hash in ast_cache:
return ast_cache[content_hash]

process = subprocess.Popen(['node', 'babelParser.js'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
stdout, stderr = process.communicate(input=file_content)
if stderr:
print("Error in parsing:", stderr)
return None
return json.loads(stdout)

def get_functions_from_file(file_content):
# Parse the output and store the AST in the cache
ast = json.loads(stdout)
ast_cache[content_hash] = ast
return ast

def get_functions_from_file(file_content):
# create ast from file content
ast = get_ast_from_js(file_content)

Expand Down Expand Up @@ -199,7 +211,7 @@ def find_function(node, function_name):

if __name__ == '__main__':
start_time = time.time()
get_function_data(repo_path='../inputData/elixirsolutions') #pass this variable if you want to run another repo than testRepo: repo_path='../inputData/elixirsolutions'
get_function_data() #pass this variable if you want to run another repo than testRepo: repo_path='../inputData/elixirsolutions'
end_time = time.time()
elapsed_time = round((end_time - start_time) / 60, 2) # convert to minutes and round to 2 decimal places
print('✅ Printed function data to outputData/test_function_changes.json ✅')
Expand Down
Loading