Skip to content

Commit 5b8e3d2

Browse files
committed
Remove bookmarks migration
When we first implemented bookmarks as an experimental feature, they were stored in local storage. People started using the feature so we decided to continue working on bookmarks to build it out into a mature feature. Most importantly, this included storing bookmarks on the server-side in order to support growing numbers of bookmarks per user and to prevent users from losing their bookmarks when clearing browsing data/switching devices. We also needed to migrate bookmarks that were currently stored locally to the server side. That means the code base had quite some code that only handled migrating the "legacy" local bookmarks to the server. As it’s been a while since we started migrating to server-side bookmarks, it should be safe to remove that migration logic now. Fix #2864
1 parent 9e0f4fa commit 5b8e3d2

File tree

13 files changed

+3
-358
lines changed

13 files changed

+3
-358
lines changed

aleph/tests/test_bookmarks_api.py

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -222,69 +222,3 @@ def test_bookmarks_delete_idempotent(self):
222222

223223
count = Bookmark.query.count()
224224
assert count == 0, count
225-
226-
def test_bookmarks_migrate(self):
227-
other_entity = self.create_entity(
228-
data={"schema": "Person", "properties": {"name": "Barack Obama"}},
229-
collection=self.collection,
230-
)
231-
index_entity(other_entity)
232-
233-
count = Bookmark.query.count()
234-
assert count == 0, count
235-
236-
body = [
237-
{"entity_id": self.entity.id, "created_at": "2005-11-22T00:00:00Z"},
238-
{"entity_id": other_entity.id, "created_at": "2009-01-20T00:00:00Z"},
239-
]
240-
res = self.client.post(
241-
"/api/2/bookmarks/migrate",
242-
headers=self.headers,
243-
data=json.dumps(body),
244-
content_type=JSON,
245-
)
246-
assert res.status_code == 201, res
247-
assert res.json["errors"] == [], res.json
248-
249-
count = Bookmark.query.count()
250-
assert count == 2, count
251-
252-
bookmarks = Bookmark.query.all()
253-
assert bookmarks[0].entity_id == self.entity.id
254-
assert bookmarks[0].created_at == datetime.datetime(2005, 11, 22), bookmarks[0]
255-
assert bookmarks[1].entity_id == other_entity.id
256-
assert bookmarks[1].created_at == datetime.datetime(2009, 1, 20), bookmarks[1]
257-
258-
def test_bookmarks_migrate_invalid_entity_id(self):
259-
invalid_entity_id = self.create_entity(
260-
{"schema": "Company"}, self.collection
261-
).id
262-
263-
body = [
264-
{"entity_id": self.entity.id, "created_at": "2022-01-01T00:00:00Z"},
265-
{"entity_id": invalid_entity_id, "created_at": "2022-01-01T00:00:00Z"},
266-
]
267-
res = self.client.post(
268-
"/api/2/bookmarks/migrate",
269-
headers=self.headers,
270-
data=json.dumps(body),
271-
content_type=JSON,
272-
)
273-
assert res.status_code == 201, res
274-
assert res.json["errors"] == [invalid_entity_id], res.json
275-
276-
count = Bookmark.query.count()
277-
assert count == 1, count
278-
279-
bookmarks = Bookmark.query.all()
280-
assert bookmarks[0].created_at == datetime.datetime(2022, 1, 1), bookmarks[0]
281-
assert bookmarks[0].entity_id == self.entity.id
282-
283-
def test_bookmarks_migrate_required_timestamp(self):
284-
res = self.client.post(
285-
"/api/2/bookmarks/migrate",
286-
headers=self.headers,
287-
data=json.dumps([{"entity_id": self.entity.id}]),
288-
content_type=JSON,
289-
)
290-
assert res.status_code == 400, res

aleph/validation/schema/bookmark.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,3 @@ BookmarkCreate:
2525
format: entity-id
2626
required:
2727
- entity_id
28-
29-
BookmarkMigrate:
30-
type: array
31-
items:
32-
type: object
33-
properties:
34-
entity_id:
35-
type: string
36-
format: entity-id
37-
created_at:
38-
type: string
39-
format: date-time
40-
required:
41-
- entity_id
42-
- created_at

aleph/views/bookmarks_api.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22
from flask import Blueprint, request
33
from werkzeug.exceptions import NotFound, Forbidden, BadRequest
4-
from sqlalchemy.dialects.postgresql import insert as postgres_insert
54

65
from aleph.core import db
76
from aleph.search import DatabaseQueryResult
@@ -124,58 +123,3 @@ def delete(entity_id):
124123
db.session.commit()
125124

126125
return "", 204
127-
128-
129-
@blueprint.route("/api/2/bookmarks/migrate", methods=["POST"])
130-
def migrate():
131-
"""Migrate bookmarks.
132-
---
133-
post:
134-
summary: Migrate bookmarks
135-
tags: [Bookmarks]
136-
requestBody:
137-
content:
138-
application/json:
139-
schema:
140-
$ref: '#/components/schemas/BookmarkMigrate'
141-
responses:
142-
'201':
143-
description: Created
144-
content:
145-
application/json:
146-
schema:
147-
type: object
148-
properties:
149-
errors:
150-
items:
151-
type: string
152-
format: entity-id
153-
"""
154-
require(request.authz.session_write)
155-
data = parse_request("BookmarkMigrate")
156-
values = []
157-
errors = []
158-
159-
for bookmark in data:
160-
try:
161-
entity = get_index_entity(bookmark.get("entity_id"))
162-
except (NotFound, Forbidden):
163-
errors.append(bookmark.get("entity_id"))
164-
continue
165-
values.append(
166-
{
167-
"role_id": request.authz.id,
168-
"entity_id": bookmark.get("entity_id"),
169-
"collection_id": entity.get("collection_id"),
170-
"created_at": bookmark.get("created_at"),
171-
}
172-
)
173-
174-
stmt = postgres_insert(Bookmark).values(values)
175-
stmt = stmt.on_conflict_do_nothing(
176-
index_elements=[Bookmark.role_id, Bookmark.entity_id],
177-
)
178-
db.session.execute(stmt)
179-
db.session.commit()
180-
181-
return jsonify({"errors": errors}, 201)

ui/src/actions/bookmarkActions.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,3 @@ export const deleteBookmark = asyncActionCreator(
1717
(entity) => async () => await endpoint.delete(`bookmarks/${entity.id}`),
1818
{ name: 'DELETE_BOOKMARK' }
1919
);
20-
21-
export const migrateLocalBookmarks = asyncActionCreator(
22-
(bookmarks) => async () => {
23-
const body = bookmarks.map((bookmark) => ({
24-
entity_id: bookmark.id,
25-
created_at: new Date(bookmark.bookmarkedAt).toISOString(),
26-
}));
27-
const response = await endpoint.post('bookmarks/migrate', body);
28-
return { bookmarks, response };
29-
},
30-
{ name: 'MIGRATE_BOOKMARKS' }
31-
);

ui/src/actions/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export {
7070
queryBookmarks,
7171
createBookmark,
7272
deleteBookmark,
73-
migrateLocalBookmarks,
7473
} from './bookmarkActions';
7574

7675
export { createAction };

ui/src/app/storage.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ export const loadState = () => {
66
return {};
77
}
88

9-
const storedState = JSON.parse(json);
10-
11-
// TODO: Remove after deadline
12-
// See https://github.com/alephdata/aleph/issues/2864
13-
storedState.localBookmarks = storedState.bookmarks;
14-
delete storedState.bookmarks;
15-
16-
return storedState;
9+
return JSON.parse(json);
1710
} catch (e) {
1811
// eslint-disable-next-line
1912
console.error('could not load state', e);

ui/src/app/store.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,11 @@ const store = createStore(
2121

2222
store.subscribe(
2323
throttle(() => {
24-
const { session, config, messages, localBookmarks } = store.getState();
24+
const { session, config, messages } = store.getState();
2525

2626
saveState({
2727
session,
2828
config,
29-
30-
// TODO: Remove after deadline
31-
// See https://github.com/alephdata/aleph/issues/2864
32-
bookmarks: localBookmarks,
33-
3429
// Do not persist the actual messages, only the dismissed message IDs.
3530
messages: { ...messages, messages: [] },
3631
});

ui/src/components/common/BookmarksDrawer.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { FC } from 'react';
22
import { FormattedMessage } from 'react-intl';
33
import { useSelector } from 'react-redux';
44
import { Classes, Drawer, DrawerSize } from '@blueprintjs/core';
5-
import { selectLocalBookmarks, selectConfigValue } from 'selectors';
6-
import BookmarksMigration from './BookmarksMigration';
75
import BookmarksList from './BookmarksList';
86

97
import './BookmarksDrawer.scss';
@@ -17,12 +15,6 @@ const BookmarksDrawer: FC<BookmarksDrawerProps> = ({
1715
isOpen,
1816
toggleDialog,
1917
}) => {
20-
const localBookmarks = useSelector(selectLocalBookmarks);
21-
const migrationCompleted = useSelector((state) =>
22-
selectConfigValue(state, 'bookmarksMigrationCompleted')
23-
);
24-
const showMigration = localBookmarks.length > 0 && !migrationCompleted;
25-
2618
const title = (
2719
<FormattedMessage id="bookmarks.title" defaultMessage="Your bookmarks" />
2820
);
@@ -39,11 +31,7 @@ const BookmarksDrawer: FC<BookmarksDrawerProps> = ({
3931
>
4032
<div className={Classes.DRAWER_BODY}>
4133
<div className="BookmarksDrawer__content">
42-
{showMigration ? (
43-
<BookmarksMigration />
44-
) : (
45-
<BookmarksList onNavigate={toggleDialog} />
46-
)}
34+
<BookmarksList onNavigate={toggleDialog} />
4735
</div>
4836
</div>
4937
</Drawer>

ui/src/components/common/BookmarksMigration.scss

Lines changed: 0 additions & 4 deletions
This file was deleted.

ui/src/components/common/BookmarksMigration.tsx

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)