Commit 126c936
committed
Optimize models and views
1. Refactored web/models.py
* Added helper methods to the Language class to encapsulate "completeness" logic:
* is_concept_complete(concept_key): Checks if a concept has code or a comment.
* is_category_incomplete(category_concepts_keys): Determines if any concept in a category is missing required data.
* has_any_implemented_in_category(category_concepts_keys): Checks if a language implements at least one concept in a category.
* Implemented simple in-memory caching for MetaInfo and MetaStructure to avoid redundant file I/O operations when loading JSON metadata and structure files.
2. Optimized web/views.py
* Simplified the concepts view by leveraging the new Language model methods, making the logic much more readable and maintainable.
* Optimized syntax highlighting by pre-fetching lexers for each language once per request, instead of looking them up for every single concept.
* Updated concepts_data, format_code_for_display, and format_comment_for_display to accept pre-fetched lexers, reducing overhead during page rendering.
3. Verification
* Verified that all existing unit tests pass.
* Ensured that the logic for determining "incomplete" status for languages and categories remains consistent with the original implementation but is now more efficient.1 parent 7beadf7 commit 126c936
2 files changed
+80
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
| |||
210 | 217 | | |
211 | 218 | | |
212 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
213 | 251 | | |
214 | 252 | | |
215 | 253 | | |
| |||
232 | 270 | | |
233 | 271 | | |
234 | 272 | | |
| 273 | + | |
| 274 | + | |
235 | 275 | | |
236 | 276 | | |
237 | 277 | | |
238 | 278 | | |
239 | 279 | | |
240 | 280 | | |
241 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
242 | 287 | | |
243 | 288 | | |
244 | 289 | | |
245 | 290 | | |
246 | 291 | | |
247 | 292 | | |
| 293 | + | |
| 294 | + | |
248 | 295 | | |
249 | 296 | | |
250 | 297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
194 | | - | |
| 195 | + | |
| 196 | + | |
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
199 | | - | |
| 201 | + | |
200 | 202 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
215 | 215 | | |
216 | 216 | | |
217 | | - | |
218 | | - | |
219 | | - | |
| 217 | + | |
| 218 | + | |
220 | 219 | | |
221 | 220 | | |
222 | 221 | | |
| |||
321 | 320 | | |
322 | 321 | | |
323 | 322 | | |
324 | | - | |
| 323 | + | |
325 | 324 | | |
326 | 325 | | |
327 | 326 | | |
328 | 327 | | |
329 | 328 | | |
330 | 329 | | |
| 330 | + | |
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | | - | |
| 337 | + | |
| 338 | + | |
338 | 339 | | |
339 | 340 | | |
340 | 341 | | |
| |||
357 | 358 | | |
358 | 359 | | |
359 | 360 | | |
360 | | - | |
| 361 | + | |
361 | 362 | | |
362 | 363 | | |
363 | 364 | | |
364 | 365 | | |
365 | 366 | | |
366 | 367 | | |
| 368 | + | |
367 | 369 | | |
368 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
369 | 379 | | |
370 | 380 | | |
371 | 381 | | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
| 382 | + | |
376 | 383 | | |
377 | 384 | | |
378 | 385 | | |
| |||
0 commit comments