Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/filterStorage.js

Issue 29899601: Issue 7015 - Serialize subscriptions for *exportData in one loop (Closed)
Patch Set: Created Oct. 3, 2018, 3:53 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 parser(null); 436 parser(null);
437 return this.saveToDisk(); 437 return this.saveToDisk();
438 }); 438 });
439 }, 439 },
440 440
441 /** 441 /**
442 * Generator serializing filter data and yielding it line by line. 442 * Generator serializing filter data and yielding it line by line.
443 */ 443 */
444 *exportData() 444 *exportData()
445 { 445 {
446 // Do not persist external subscriptions
447 let subscriptions = [];
448 for (let subscription of this.subscriptions())
449 {
450 if (!(subscription instanceof ExternalSubscription))
451 subscriptions.push(subscription);
452 }
453
454 yield "# Adblock Plus preferences"; 446 yield "# Adblock Plus preferences";
455 yield "version=" + formatVersion; 447 yield "version=" + formatVersion;
456 448
457 let saved = new Set(); 449 let saved = new Set();
458 let buf = []; 450 let buf = [];
459 451
460 // Save subscriptions 452 // Save subscriptions
461 for (let subscription of subscriptions) 453 for (let subscription of this.subscriptions())
462 { 454 {
455 // Do not persist external subscriptions
456 if (subscription instanceof ExternalSubscription)
457 continue;
458
463 yield ""; 459 yield "";
460 subscription.serialize(buf);
464 461
465 subscription.serialize(buf);
466 if (subscription.filters.length) 462 if (subscription.filters.length)
467 { 463 {
468 buf.push("", "[Subscription filters]"); 464 buf.push("", "[Subscription filters]");
469 subscription.serializeFilters(buf); 465 subscription.serializeFilters(buf);
470 } 466 }
467
471 for (let line of buf) 468 for (let line of buf)
472 yield line; 469 yield line;
470
473 buf.splice(0); 471 buf.splice(0);
Sebastian Noack 2018/10/03 16:33:24 While optimizing this code, you might want conside
474 }
475 472
476 // Save filter data 473 // Save filter data
477 for (let subscription of subscriptions)
478 {
479 for (let filter of subscription.filters) 474 for (let filter of subscription.filters)
480 { 475 {
481 if (!saved.has(filter.text)) 476 if (!saved.has(filter.text))
482 { 477 {
483 filter.serialize(buf); 478 filter.serialize(buf);
484 saved.add(filter.text); 479 saved.add(filter.text);
485 for (let line of buf) 480 for (let line of buf)
486 yield line; 481 yield line;
487 buf.splice(0); 482 buf.splice(0);
488 } 483 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 * @param {Subscription} subscription filter subscription to be removed 645 * @param {Subscription} subscription filter subscription to be removed
651 */ 646 */
652 function removeSubscriptionFilters(subscription) 647 function removeSubscriptionFilters(subscription)
653 { 648 {
654 if (!FilterStorage.knownSubscriptions.has(subscription.url)) 649 if (!FilterStorage.knownSubscriptions.has(subscription.url))
655 return; 650 return;
656 651
657 for (let filter of subscription.filters) 652 for (let filter of subscription.filters)
658 filter.removeSubscription(subscription); 653 filter.removeSubscription(subscription);
659 } 654 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld