Skip to content

Commit 6925b39

Browse files
authored
Merge pull request #14 from oslabs-beta/cleanup
Clean code, remove console logs, add comments, remove vestigial files
2 parents 87811df + b2601aa commit 6925b39

28 files changed

+85
-2826
lines changed

.travis.yml

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

ObsidianWrapper/ObsidianWrapper.jsx

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function ObsidianWrapper(props) {
2929
}
3030

3131
// once cache is initialized, cannot setCache
32-
// when tested, setCache breaks the whole app if trying to switch while in use
33-
// to successfully change between algo types, kill the server, change the algo type in wrapper, then restart server
32+
// state for cache is initialized based on developer settings in wrapper
33+
// to successfully change between algo types for testing, kill the server, change the algo type in wrapper, then restart server
3434
const [cache, setCache] = React.useState(setAlgoCap(algo, capacity));
3535

3636
// FOR DEVTOOL - listening for message from content.js to be able to send algo type and capacity to devtool
@@ -55,7 +55,7 @@ function ObsidianWrapper(props) {
5555
cacheRead = !caching ? false : true,
5656
cacheWrite = !caching ? false : true,
5757
pollInterval = null,
58-
wholeQuery = true, //Note: logic for false is currently nonfunctional
58+
wholeQuery = false, //Note: logic for true is currently nonfunctional
5959
} = options;
6060

6161
// when pollInterval is not null the query will be sent to the server every inputted number of milliseconds
@@ -71,24 +71,18 @@ function ObsidianWrapper(props) {
7171
return interval;
7272
}
7373

74-
// when cacheRead set to true
74+
// when cacheRead set to true & we are utilizing client side caching
7575
if (cacheRead && caching) {
7676
let resObj;
7777
// when the developer decides to only utilize whole query for cache
78-
if (!wholeQuery) resObj = await cache.readWholeQuery(query);
78+
if (wholeQuery) resObj = await cache.readWholeQuery(query);
79+
// attempt to read from the cache
7980
else resObj = await cache.read(query);
8081
// check if query is stored in cache
8182
if (resObj) {
8283
// returning cached response as a promise
8384
const cacheHitResponseTime = Date.now() - startTime;
8485

85-
// resObj['time'] = cacheHitResponseTime;
86-
87-
console.log(
88-
"From cacheRead: Here's the response time on the front end: ",
89-
cacheHitResponseTime
90-
);
91-
9286
// FOR DEVTOOL - sends message to content.js with query metrics when query is a hit
9387
window.postMessage({
9488
type: 'query',
@@ -102,19 +96,19 @@ function ObsidianWrapper(props) {
10296
}
10397
// execute graphql fetch request if cache miss
10498
return new Promise((resolve, reject) => resolve(hunt(query)));
105-
// when cacheRead set to false
10699
}
100+
// when cacheRead set to false & not using client-side cache
107101
if (!cacheRead || !caching) {
108102
return new Promise((resolve, reject) => resolve(hunt(query)));
109103
}
110104

111-
// when cache miss or on intervals or not looking in the cache
105+
// function to be called on cache miss or on intervals or not looking in the cache
112106
async function hunt(query) {
113-
if (wholeQuery) query = insertTypenames(query);
107+
if (!wholeQuery) query = insertTypenames(query);
114108
try {
115109
let resJSON;
110+
// IF WE ARE USING PERSIST QUERIES
116111
if (persistQueries) {
117-
// IF WE ARE USING PERSIST QUERIES
118112
// SEND THE HASH
119113
const hash = sha256(query, 'utf8', 'hex');
120114
resJSON = await fetch(endpoint, {
@@ -140,8 +134,8 @@ function ObsidianWrapper(props) {
140134

141135
}
142136

137+
// IF WE ARE NOT USING PERSIST QUERIES
143138
} else {
144-
// IF WE ARE NOT USING PERSIST QUERIES
145139
// JUST SEND THE QUERY ONLY
146140
resJSON = await fetch(endpoint, {
147141
method: 'POST',
@@ -157,18 +151,11 @@ function ObsidianWrapper(props) {
157151
const deepResObj = { ...resObj };
158152
// update result in cache if cacheWrite is set to true
159153
if (cacheWrite && caching && resObj.data[Object.keys(resObj.data)[0]] !== null) {
160-
if (!wholeQuery) cache.writeWholeQuery(query, deepResObj);
154+
if (wholeQuery) cache.writeWholeQuery(query, deepResObj);
161155
else if(resObj.data[Object.keys(resObj.data)[0]].length > cache.capacity) console.log('Please increase cache capacity');
162156
else cache.write(query, deepResObj, searchTerms);
163157
}
164158
const cacheMissResponseTime = Date.now() - startTime;
165-
166-
// resObj['time'] = cacheMissResponseTime;
167-
168-
console.log(
169-
"After the hunt: Here's the response time on the front end: ",
170-
cacheMissResponseTime
171-
);
172159

173160
// FOR DEVTOOL - sends message to content.js when query is a miss
174161
window.postMessage({
@@ -203,7 +190,7 @@ function ObsidianWrapper(props) {
203190
cacheWrite = !caching ? false : true,
204191
toDelete = false,
205192
update = null,
206-
writeThrough = true, // not true
193+
writeThrough = true, // unsure if boolean is symantically backwards or not
207194
} = options;
208195
try {
209196
if (!writeThrough) {
@@ -216,9 +203,6 @@ function ObsidianWrapper(props) {
216203
endpoint
217204
);
218205
const deleteMutationResponseTime = Date.now() - startTime;
219-
// NOTE - from OLD DEVTOOLS - chrome.runtime.sendMessage(chromeExtensionId, {
220-
// deleteMutationResponseTime: deleteMutationResponseTime,
221-
// });
222206
return responseObj;
223207
} else {
224208
// for add mutation
@@ -237,15 +221,9 @@ function ObsidianWrapper(props) {
237221
// GQL call to make changes and synchronize database
238222
console.log('WriteThrough - false ', responseObj);
239223
const addOrUpdateMutationResponseTime = Date.now() - startTime;
240-
// NOTE - from OLD DEVTOOLS - chrome.runtime.sendMessage(chromeExtensionId, {
241-
// addOrUpdateMutationResponseTime: addOrUpdateMutationResponseTime,
242-
// });
243224
return responseObj;
244225
}
245226
} else {
246-
// copy-paste mutate logic from 4.
247-
248-
// use cache.write instead of cache.writeThrough
249227
const responseObj = await fetch(endpoint, {
250228
method: 'POST',
251229
headers: {

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Obsidian](./assets/logoSilver.jpg)
1+
![Obsidian](./assets/logo.jpg)
22

33
<div align="center">GraphQL, built for Deno.</div>
44

@@ -24,9 +24,9 @@
2424

2525
- (New!) Support for W-TinyLFU client-side cache that brings great hit-ratio performance with minimal memory overhead
2626
- (New!) Option to provide Obsidian with the search types your application uses, allowing data cached from complete dataset pulls to be accessible later on in searches for individual items
27+
- (New!) Refactored server-side caching with Redis
2728
- (New!) Rebuilt developer tool for Obsidian 8.0 for testing and analytics related to the new client caching options
2829
- (New!) Option for persistant queries, allowing only a smaller hash to be sent to the server on client-side cache misses, minimizing the cost of queries. Note that while this will increase the performance for frequent, repeat queries, you may see a performance drop for new queries that haven't yet been persisted
29-
- Server-side cache invalidation only on affected entries
3030
- Flexible cache responds with only data requested from selected fields
3131
- GraphQL query abstraction and caching improving the performance of your app
3232
- SSR React wrapper, allowing you to cache in browser
@@ -70,6 +70,7 @@ const GraphQLRouter =
7070
useCache: true, //Boolean to toggle all cache functionality
7171
usePlayground: true, //Boolean to allow for graphQL playground
7272
persistQueries: true, //Boolean to toggle the use of persistant queries
73+
searchTerms: [] //Optional array to allow board queries to store according to search fields so individual searches are found in cache
7374
customIdentifier: ['id', '__typename'],
7475
mutationTableMap = {}, //Object where keys are add mutation types and value is an array of affected tables (e.g. {addPlants: ['plants'], addMovie: ['movies']})
7576
};
@@ -170,7 +171,7 @@ const MovieApp = () => {
170171

171172
Information and instructions on how to use our developer tool can be found here <br/>
172173
works with Obsidian 8.0 <br/>
173-
[oslabs-beta/obsidian-developer-tool](https://github.com/oslabs-beta/obsidian-8.0-devtool)
174+
[oslabs-beta/obsidian-developer-tool](https://github.com/oslabs/obsidian-devtool)
174175

175176
## Obsidian 8.0 Demo
176177

@@ -184,6 +185,7 @@ Working demo to install locally in docker:
184185

185186
## Features In Progress
186187

188+
-
187189
- Ability to store/read only the whole query
188190
- Hill Climber optimization for W-TinyLFU cache size allocation
189191
- Developer Tool View Cache component, and Playground component

assets/logo.png

50.4 KB
Loading

assets/logoSilver.jpg

-197 KB
Binary file not shown.

0 commit comments

Comments
 (0)