Skip to content

Commit

Permalink
Improved the query caching
Browse files Browse the repository at this point in the history
  • Loading branch information
scmmmh committed Nov 24, 2023
1 parent 453bc95 commit ab40767
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 250 deletions.
5 changes: 4 additions & 1 deletion museum_map/models/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ class ItemModel(BaseModel):
@classmethod
def convert_model_to_ids(cls, value: any) -> int:
"""Convert the child models to ids."""
return value.id
if value is not None:
return value.id
else:
return None
171 changes: 86 additions & 85 deletions museum_map/server/frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,91 @@
<Route path="/floor/:fid/room/:rid/*"><Room /></Route>
<NotFoundRoute><Lobby/></NotFoundRoute>
</main>
<TrackingConfig />
{#if $isBusy}
<div
transition:fade
class="fixed left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2 z-50 p-4 bg-neutral-700 shadow-2xl rounded-2xl"
role="alert"
>
<span class="sr-only">Loading... Please wait...</span>
<svg
class="w-20 h-20 text-white stroke-current"
viewBox="0 0 45 45"
xmlns="http://www.w3.org/2000/svg"
>
<g
fill="none"
fill-rule="evenodd"
transform="translate(1 1)"
stroke-width="2"
>
<circle cx="22" cy="22" r="6" stroke-opacity="0">
<animate
attributeName="r"
begin="1.5s"
dur="3s"
values="6;22"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="stroke-opacity"
begin="1.5s"
dur="3s"
values="1;0"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="stroke-width"
begin="1.5s"
dur="3s"
values="2;0"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="22" cy="22" r="6" stroke-opacity="0">
<animate
attributeName="r"
begin="3s"
dur="3s"
values="6;22"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="stroke-opacity"
begin="3s"
dur="3s"
values="1;0"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="stroke-width"
begin="3s"
dur="3s"
values="2;0"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="22" cy="22" r="8">
<animate
attributeName="r"
begin="0s"
dur="1.5s"
values="6;1;2;3;4;5;6"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
</g>
</svg>
</div>
{/if}
{:else}
<div
transition:fade
Expand Down Expand Up @@ -260,90 +345,6 @@
</div>
{/if}
{#if $isBusy}
<div
transition:fade
class="fixed left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2 z-50 p-4 bg-neutral-700 shadow-2xl rounded-2xl"
role="alert"
>
<span class="sr-only">Loading... Please wait...</span>
<svg
class="w-20 h-20 text-white stroke-current"
viewBox="0 0 45 45"
xmlns="http://www.w3.org/2000/svg"
>
<g
fill="none"
fill-rule="evenodd"
transform="translate(1 1)"
stroke-width="2"
>
<circle cx="22" cy="22" r="6" stroke-opacity="0">
<animate
attributeName="r"
begin="1.5s"
dur="3s"
values="6;22"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="stroke-opacity"
begin="1.5s"
dur="3s"
values="1;0"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="stroke-width"
begin="1.5s"
dur="3s"
values="2;0"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="22" cy="22" r="6" stroke-opacity="0">
<animate
attributeName="r"
begin="3s"
dur="3s"
values="6;22"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="stroke-opacity"
begin="3s"
dur="3s"
values="1;0"
calcMode="linear"
repeatCount="indefinite"
/>
<animate
attributeName="stroke-width"
begin="3s"
dur="3s"
values="2;0"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
<circle cx="22" cy="22" r="8">
<animate
attributeName="r"
begin="0s"
dur="1.5s"
values="6;1;2;3;4;5;6"
calcMode="linear"
repeatCount="indefinite"
/>
</circle>
</g>
</svg>
</div>
{/if}
</main>
<TrackingConfig />-->
-->
</div>
8 changes: 4 additions & 4 deletions museum_map/server/frontend/src/components/Thumbnail.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { createEventDispatcher } from "svelte";
import { derived } from "svelte/store";
import { tracker, rooms, fetchRooms, floors } from "../store";
import { tracker, rooms, floors } from "../store";
export let item: Item;
export let noLink = false;
Expand All @@ -27,10 +27,10 @@
dispatch("load");
}
const itemRoom = derived(rooms, (rooms) => {
const room = rooms[item.room];
const itemRoom = derived(rooms, (roomsDict) => {
const room = roomsDict[item.room];
if (room === undefined) {
fetchRooms([item.room]);
rooms.fetch([item.room]);
}
return room;
});
Expand Down
4 changes: 1 addition & 3 deletions museum_map/server/frontend/src/routes/Floor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
floors,
floorTopics,
currentFloor,
fetchRooms,
fetchItems,
currentRooms,
localPreferences,
matchingFloors,
Expand Down Expand Up @@ -263,7 +261,7 @@
});
} else {
location.push(
"/room/" + objectsClicked[0].getData("room_id")
"/floor/" + $currentFloor?.id + "/room/" + objectsClicked[0].getData("room_id")
);
}
}
Expand Down
11 changes: 6 additions & 5 deletions museum_map/server/frontend/src/routes/Item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
let previousItem = null;
for (const item of currentItems) {
if (item.id === currentItem.id) {
return previousItem;
if (previousItem) {
return previousItem;
} else if (currentItems.length > 0) {
return currentItems[currentItems.length - 1];
}
}
previousItem = item;
}
if (currentItems.length > 0) {
return currentItems[currentItems.length - 1];
}
}
return null;
},
Expand All @@ -49,7 +50,7 @@
}
}
if (currentItems.length > 0) {
return currentItems[currentItems.length - 1];
return currentItems[0];
}
}
return null;
Expand Down
6 changes: 2 additions & 4 deletions museum_map/server/frontend/src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { busyCounter, isBusy } from './busy';
import { itemOfTheDay, randomItemsSelection } from './picks';
import { floorTopics, majorCollections, floors, currentFloor } from './floors';
import { rooms, fetchRooms, currentRooms, currentRoom } from './rooms';
import { items, fetchItems, currentItems, currentItem } from './items';
import { rooms, currentRooms, currentRoom } from './rooms';
import { items, currentItems, currentItem } from './items';
import { config } from './config';
import { cachedTopics, loadTopics } from './topics';
import { localPreferences } from './preferences';
Expand All @@ -27,10 +27,8 @@ export {
currentRoom,
currentRooms,
rooms,
fetchRooms,

items,
fetchItems,
currentItems,
currentItem,

Expand Down
Loading

0 comments on commit ab40767

Please sign in to comment.