Skip to content

Commit

Permalink
count every download of repo file
Browse files Browse the repository at this point in the history
Previously the render_generate_repo_file was memoized() so subsequent downloads was not counted.
Now the function is not memoized() and CounterStatLogic.incr() is always called and only rest of the function is memoized().
  • Loading branch information
xsuchy authored and praiskup committed Jan 5, 2024
1 parent 3f1413a commit 6fb74a0
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,18 @@ def _render_external_repo_template(dep, copr_dir, mock_chroot, dep_idx):
url=baseurl) + "\n"


@cache.memoize(timeout=5*60)
def render_generate_repo_file(copr_dir, name_release, arch=None):
name = helpers.get_stat_name(
CounterStatType.REPO_DL,
copr_dir=copr_dir,
name_release=name_release,
)
CounterStatLogic.incr(name=name, counter_type=CounterStatType.REPO_DL)
db.session.commit()
return render_generate_repo_file_cached(copr_dir, name_release, arch=arch)

@cache.memoize(timeout=5*60)
def render_generate_repo_file_cached(copr_dir, name_release, arch=None):
copr = copr_dir.copr

# redirect the aliased chroot only if it is not enabled yet
Expand Down Expand Up @@ -964,14 +974,6 @@ def render_generate_repo_file(copr_dir, name_release, arch=None):
response.headers["Content-Disposition"] = \
"filename={0}.repo".format(copr_dir.repo_name)

name = helpers.get_stat_name(
CounterStatType.REPO_DL,
copr_dir=copr_dir,
name_release=name_release,
)
CounterStatLogic.incr(name=name, counter_type=CounterStatType.REPO_DL)
db.session.commit()

return response


Expand Down

0 comments on commit 6fb74a0

Please sign in to comment.