Skip to content

Commit 9df1e65

Browse files
hellcpjwise
authored andcommitted
Count the installs for apps
1 parent 8869ee9 commit 9df1e65

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

appstore/locker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,15 @@ def app_locker(app_uuid):
107107
return 'invalid app', 400
108108
entry = LockerEntry(app=app, user_id=uid, user_token=secrets.token_urlsafe(32))
109109
db.session.add(entry)
110+
App.query.filter_by(app_uuid=app_uuid).update({'installed': App.installed + 1})
110111
db.session.commit()
111112
return jsonify(application=jsonify_locker_app(entry))
112113
elif request.method == 'DELETE':
113114
entry = LockerEntry.query.join(LockerEntry.app).filter(LockerEntry.user_id == uid,
114115
App.app_uuid == app_uuid).one_or_none()
115116
if entry:
116117
db.session.delete(entry)
118+
App.query.filter_by(app_uuid=app_uuid).update({'installed': App.installed - 1})
117119
db.session.commit()
118120
return '', 204
119121

appstore/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class App(db.Model):
7676
website = db.Column(db.String)
7777
visible = db.Column(db.Boolean, default=True, server_default='TRUE', nullable=False)
7878
timeline_token = db.Column(db.String, index=True)
79+
installs = db.Column(db.Integer, index=True)
7980

8081

8182
category_banner_apps = Table('category_banner_apps', db.Model.metadata,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Add installs to apps
2+
3+
Revision ID: d820786671c8
4+
Revises: 705e61509d00
5+
Create Date: 2025-11-17 23:57:40.337316
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'd820786671c8'
14+
down_revision = '705e61509d00'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column('apps', sa.Column('installs', sa.Integer(), nullable=True))
22+
op.execute("""
23+
UPDATE apps AS ap
24+
SET installs = sub.count
25+
FROM (
26+
SELECT app_id, COUNT(*) AS count
27+
FROM locker_entries
28+
GROUP BY app_id
29+
) AS sub
30+
WHERE ap.id = sub.app_id
31+
""")
32+
op.create_index(op.f('ix_apps_installs'), 'apps', ['installs'], unique=False)
33+
# ### end Alembic commands ###
34+
35+
36+
def downgrade():
37+
# ### commands auto generated by Alembic - please adjust! ###
38+
op.drop_index(op.f('ix_apps_installs'), table_name='apps')
39+
op.drop_column('apps', 'installs')
40+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)