Skip to content

Commit f6532e0

Browse files
authored
Don't index apps that are hidden (#52)
1 parent c68b28b commit f6532e0

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

appstore/commands.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,18 @@ def generate_index():
404404
apps = App.query.order_by(App.id)
405405
result = []
406406
for app in apps:
407-
result.append(algolia_app(app))
407+
if app.visible:
408+
result.append(algolia_app(app))
408409
print(flask.json.dumps(result, indent=2))
409410

411+
412+
@apps.command('remove-hidden-apps-index')
413+
def remove_hidden_apps_index():
414+
apps = App.query.filter_by(visible=False).order_by(App.id)
415+
if algolia_index:
416+
algolia_index.delete_objects([app.id for app in apps])
417+
418+
410419
@apps.command('update-patched-release')
411420
@click.argument('new_pbw')
412421
@click.argument('patchlvl')
@@ -513,7 +522,7 @@ def path(base):
513522
upload_pbw(release, path(pbw_file))
514523
db.session.commit()
515524

516-
if algolia_index:
525+
if algolia_index and app_obj.visible:
517526
algolia_index.partial_update_objects([algolia_app(app_obj)], { 'createIfNotExists': True })
518527

519528
@apps.command('update-app')
@@ -562,9 +571,12 @@ def path(base):
562571
print(f"Created release {release.id}")
563572
upload_pbw(release, path(pbw_file))
564573
db.session.commit()
565-
574+
566575
if algolia_index:
567-
algolia_index.partial_update_objects([algolia_app(app_obj)], { 'createIfNotExists': True })
576+
if app_obj.visible:
577+
algolia_index.partial_update_objects([algolia_app(app_obj)], { 'createIfNotExists': False })
578+
else:
579+
algolia_index.delete_objects([app_obj.id])
568580

569581

570582
def init_app(app):

appstore/dev_portal_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def add_heart(app_id):
131131
return
132132
except IntegrityError:
133133
return "already hearted", 400
134-
if algolia_index:
134+
if algolia_index and app.visible:
135135
algolia_index.partial_update_object({'objectID': app_id, 'hearts': app.hearts}, no_create=True)
136136
return 'ok'
137137

@@ -147,7 +147,7 @@ def remove_heart(app_id):
147147
db.session.delete(like)
148148
App.query.filter_by(id=app_id).update({'hearts': App.hearts - 1})
149149
db.session.commit()
150-
if algolia_index:
150+
if algolia_index and app.visible:
151151
algolia_index.partial_update_object({'objectID': app_id, 'hearts': app.hearts}, no_create=True)
152152
return 'ok'
153153

appstore/developer_portal_api.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ def submit_new_app():
157157
app_is_timeline_enabled = True
158158
timeline_token = secrets.token_urlsafe(32)
159159

160+
is_visible = True
161+
if 'visible' in params and params['visible'] == 'false':
162+
is_visible = False
163+
160164
# Remove any platforms with no screenshots
161165
screenshots = {k: v for k, v in screenshots.items() if v}
162166
app_obj = App(
@@ -182,6 +186,7 @@ def submit_new_app():
182186
type=params['type'],
183187
timeline_enabled=app_is_timeline_enabled,
184188
timeline_token=timeline_token,
189+
visible=is_visible,
185190
website=params['website'] if 'website' in params else "",
186191
)
187192
db.session.add(app_obj)
@@ -196,7 +201,7 @@ def submit_new_app():
196201
upload_pbw(release, request.files['pbw'])
197202
db.session.commit()
198203

199-
if algolia_index:
204+
if algolia_index and app_obj.visible:
200205
algolia_index.partial_update_objects([algolia_app(app_obj)], { 'createIfNotExists': True })
201206

202207
try:
@@ -272,7 +277,10 @@ def update_app_fields(app_id):
272277

273278
db.session.commit()
274279
if algolia_index:
275-
algolia_index.partial_update_objects([algolia_app(app)], { 'createIfNotExists': False })
280+
if app.visible:
281+
algolia_index.partial_update_objects([algolia_app(app)], { 'createIfNotExists': False })
282+
else:
283+
algolia_index.delete_objects([app_id])
276284

277285
return jsonify(success=True, id=app.id)
278286

0 commit comments

Comments
 (0)