Skip to content

Deprecate/Remove File.downloads as currently exposed #2480

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

Merged
merged 1 commit into from
Oct 7, 2017
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions tests/unit/legacy/api/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_detail_renders(self, pyramid_config, db_request):
"1.0": [
{
"comment_text": None,
"downloads": 0,
"downloads": -1,
"filename": files[0].filename,
"has_sig": True,
"md5_digest": files[0].md5_digest,
Expand All @@ -238,7 +238,7 @@ def test_detail_renders(self, pyramid_config, db_request):
"2.0": [
{
"comment_text": None,
"downloads": 0,
"downloads": -1,
"filename": files[1].filename,
"has_sig": True,
"md5_digest": files[1].md5_digest,
Expand All @@ -260,7 +260,7 @@ def test_detail_renders(self, pyramid_config, db_request):
"urls": [
{
"comment_text": None,
"downloads": 0,
"downloads": -1,
"filename": files[1].filename,
"has_sig": True,
"md5_digest": files[1].md5_digest,
Expand Down
23 changes: 6 additions & 17 deletions tests/unit/legacy/api/test_xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import collections
import datetime
import random

import pretend
import pytest
Expand Down Expand Up @@ -253,21 +251,12 @@ def test_user_packages(db_request):


@pytest.mark.parametrize("num", [None, 1, 5])
def test_top_packages(db_request, num):
projects = [ProjectFactory.create() for _ in range(10)]
files = collections.Counter()
for project in projects:
releases = [ReleaseFactory.create(project=project) for _ in range(3)]
for release in releases:
file_ = FileFactory.create(
release=release,
filename="{}-{}.tar.gz".format(project.name, release.version),
downloads=random.randint(0, 1000),
)
files[project.name] += file_.downloads
def test_top_packages(num):
with pytest.raises(xmlrpc.XMLRPCWrappedError) as exc:
xmlrpc.top_packages(pretend.stub(), num)

assert set(xmlrpc.top_packages(db_request, num)) == \
set(files.most_common(num))
assert exc.value.faultString == \
"RuntimeError: This API has been removed. Please Use BigQuery instead."


def test_package_releases(db_request):
Expand Down Expand Up @@ -390,7 +379,7 @@ def test_release_urls(db_request):
"has_sig": file_.has_signature,
"upload_time": file_.upload_time,
"comment_text": file_.comment_text,
"downloads": file_.downloads,
"downloads": -1,
"url": urls[0],
}
]
Expand Down
4 changes: 3 additions & 1 deletion warehouse/legacy/api/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def json_release(release, request):
"sha256": f.sha256_digest,
},
"size": f.size,
"downloads": f.downloads,
# TODO: Remove this once we've had a long enough time with it
# here to consider it no longer in use.
"downloads": -1,
"upload_time": f.upload_time.strftime("%Y-%m-%dT%H:%M:%S"),
"url": request.route_url("packaging.file", path=f.path),
}
Expand Down
17 changes: 5 additions & 12 deletions warehouse/legacy/api/xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,10 @@ def user_packages(request, username):

@pypi_xmlrpc(method="top_packages")
def top_packages(request, num=None):
fdownloads = func.sum(File.downloads).label("downloads")

downloads = (
request.db.query(File.name, fdownloads)
.group_by(File.name)
.order_by(fdownloads.desc())
raise XMLRPCWrappedError(
RuntimeError("This API has been removed. Please Use BigQuery instead.")
)

if num is not None:
downloads = downloads.limit(num)

return [(d[0], d[1]) for d in downloads.all()]


@pypi_xmlrpc(method="package_releases")
def package_releases(request, package_name, show_hidden=False):
Expand Down Expand Up @@ -262,7 +253,9 @@ def release_urls(request, package_name, version):
"has_sig": f.has_signature,
"upload_time": f.upload_time,
"comment_text": f.comment_text,
"downloads": f.downloads,
# TODO: Remove this once we've had a long enough time with it
# here to consider it no longer in use.
"downloads": -1,
"url": request.route_url("packaging.file", path=f.path),
}
for f in files
Expand Down
5 changes: 4 additions & 1 deletion warehouse/packaging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ def __table_args__(cls): # noqa
md5_digest = Column(Text, unique=True, nullable=False)
sha256_digest = Column(CIText, unique=True, nullable=False)
blake2_256_digest = Column(CIText, unique=True, nullable=False)
downloads = Column(Integer, server_default=sql.text("0"))
upload_time = Column(DateTime(timezone=False), server_default=func.now())
# We need this column to allow us to handle the currently existing "double"
# sdists that exist in our database. Eventually we should try to get rid
Expand All @@ -416,6 +415,10 @@ def __table_args__(cls): # noqa
server_default=sql.false(),
)

# TODO: Once Legacy PyPI is gone, then we should remove this column
# completely as we no longer use it.
downloads = Column(Integer, server_default=sql.text("0"))

@hybrid_property
def pgp_path(self):
return self.path + ".asc"
Expand Down